<?php # mensajes cifrados $C1 = "1010110010011110011111101110011001101100111010001111011101101011101000110010011000000101001110111010010111100100111101001010000011000001010001001001010000000010101001000011100100010011011011011011010111010011000101010111111110010011010111001001010101110001111101010000001011110100000000010010111001111010110000001101010010110101100010011111111011101101001011111001101111101111000100100001000111101111011011001011110011000100011111100001000101111000011101110101110010010100010111101111110011011011001101110111011101100110010100010001100011001010100110001000111100011011001000010101100001110011000000001110001011101111010100101110101000100100010111011000001111001110000011111111111110010111111000011011001010010011100011100001011001101110110001011101011101111110100001111011011000110001011111111101110110101101101001011110110010111101000111011001111"; $C2 = "1011110110100110000001101000010111001000110010000110110001101001111101010000101000110100111010000010011001100100111001101010001001010001000011011001010100001100111011010011111100100101000001001001011001110010010100101011111010001110010010101111110001100010100001110000110001111111001000100001001010100011100100001101010101111000100001111101111110111001000101111111101011001010000100100000001011001001010000101001110101110100001111100001011101100100011000110111110001000100010111110110111010010010011101011111111001011011001010010110100100011001010110110001001000100011011001110111010010010010110100110100000111100001111101111010011000100100110011111011001010101000100000011111010010110111001100011100001111100100110010010001111010111011110110001000111101010110101001110111001110111010011111111010100111000100111001011000111101111101100111011001111"; ##### # CHANGE THESE VARIABLES $plaintext1 = "FOR"; $pattern = "FOR"; $plaintext2 = "the"; # END ############# ############# # Below is some code that might be useful # # pinta textos cifrados C1&C2 echo "Clave binaria: $C1\n"; $l1 = strlen($C1); echo "Long: $l1\n"; echo "Clave binaria: $C2\n"; $l2 = strlen($C2); echo "Long: $l2\n"; $CA1 = ""; $CA2 = ""; for ($i=0; $i<$l1; $i=$i+7) { $char7 = substr($C1, $i, 7); $dec1 = bindec($char7); $chr1 = chr($dec1); $CA1 .= $chr1; $char7 = substr($C2, $i, 7); $dec2 = bindec($char7); $chr2 = chr($dec2); $CA2 .= $chr2; #printf ("%08b,%s\n", $dec1, $chr1); } echo "Clave ASCII 1:\n$CA1\n"; $lca1 = strlen($CA1); echo "Long: $lca1\n"; echo "Clave ASCII 2:\n$CA2\n"; $lca2 = strlen($CA2); echo "Long: $lca2\n"; echo "Texto claro 1:\n>$plaintext1<\n"; $ltc1 = strlen($plaintext1); echo "Long: $ltc1\n"; for ($desp=$ltc1; $desp<$lca1+1; $desp++) { $padl = str_pad($plaintext1, $desp, $pattern, STR_PAD_LEFT); $padr = str_pad($padl, $lca1, " ", STR_PAD_RIGHT); $lp1 = strlen($padr); echo "Clave 1: >$padr< ($lp1)\n"; $xorc1 = ""; $xorc2 = ""; for ($x = 0; $x<$lp1; $x++) { $xor1 = ord($padr[$x])^ord($C1[$x]); $xorc1 .= chr($xor1); $xor2 = ord($xor1)^ord($C2[$x]); $xorc2 .= chr($xor2); } echo "XOr C1 : $xorc1\n"; echo "XOr C2 : $xorc2\n"; } ?>