This is a puzzle asked in a contest. Given that encryption , decryption happens as per following rule/code:
Encrypt(PlainTextBytes, KeyBytes){
for(int i = 0;i < PlainTextBytes.length; i++) {
Cipherbytes[i] = PlainTextBytes[i] ^ KeyBytes[i];
}
return Cipherbytes;
}
Decrypt(Cipherbytes, Keybytes){
for(int i = 0; i < Cipherbytes.length; i++) {
Plaintextbytes[i] = Cipherbytes[i] ^ Keybytes[i];
}
return Plaintextbytes;
}
Send(message){
key=Read from file "SymmetricKey.txt"
Convert key to keyBytes and message to messageBytes using ASCII encoding
print "Message to be sent: ", encrypt(messagebytes, keybytes)
}
Receive(receivedmessage){
key = Read from file "SymmetricKey.txt"
Convert key to keyBytes and receivedmessage to receivedmessageBytes using ASCII encoding
print "Message for you : " , decrypt(receivedmessagebytes, keybytes)
}
Given 3 encrypted message sequences as follows
120, 84, 25, 1, 15, 17, 42, 21, 9, 12, 3, 49, 8, 29, 82, 31, 87, 118, 88, 92, 93
125, 87, 44, 7, 31, 41, 6, 8, 17, 51, 14, 17, 42, 27, 86, 19, 66, 92, 88, 86, 7
123, 84, 16, 28, 9, 10, 4, 2, 31, 55, 7, 6, 13, 61, 91, 62, 89, 91, 83, 87, 86
Some one has discovered that there is some flaw in encryption. IMO flaw doesn't lie with code it's in Cipherbytes
. Cipherbytes
may be having some patterns so that we can decrypt this message.
Is there a way I could get the source message of these three encrypted messages?
I have look at How does one attack a two-time pad (i.e. one time pad with key reuse)? That question is different from this since that assumed that cipher text uses same pattern to encrypt in this case it's not true . I wrote simple program to test nothing prints on output.
as
char a1[ ]={120, 84, 25, 1, 15, 17, 42, 21, 9, 12, 3, 49, 8, 29, 82, 31, 87, 118, 88, 92, 93 };
char a2[ ]={125, 87, 44, 7, 31, 41, 6, 8, 17, 51, 14, 17, 42, 27, 86, 19, 66, 92, 88, 86, 7};
char a3[ ]={123, 84, 16, 28, 9, 10, 4, 2, 31, 55, 7, 6, 13, 61, 91, 62, 89, 91, 83, 87, 86 };
for(i=0;i<256;i++){
for(int l=0;l<22;l++){
s1[l] = (a1[l]^i)^a2[l];
s2[l] = (a1[l]^i)^a3[l];
}
flag=1;
for(k=0;k<22;k++){
if(s1[k]!=s2[k])flag=0;
}
if(flag){
for(int k=0;k<22;k++){
cout<<(s1[k]^a1[k]^a2[k])<<" ";
}
cout<<"\n";
}
}