There is a one time pad which works as follows:
given message "hello" and key "asdfg", it produces "hwoqu". It only works with the 26 english letters. The output is (h(7) + a(0))%26 = h(7), (e(4) + s(18))%26 = w(22) etc.
So I have two ciphertexts created as above using a single key for both ciphertexts. I'm supposed to be able to crack the plain texts without needing access to the key.
What is the procedure to do this?
So far, I've tried XORing the two cipher texts, i.e. for each letter in c1 and c2, convert to its corresponding numeric value and XOR the nth letter of c1 with nth letter of c2, to genate c3.
I'm then supposed to use that with a guess word like "the" by exoring that against c3. This is the part where I'm stuck, I don't know what I'm supposed to be looking for here.
Edit:
So since its a addition rather than a XOR, this is what I wrote:
c1 = "ujhantamawmuzvgkterrykub"
c2 = "bpgxmkymbbpyxmogoehdefgh"
pad encrypt and decrypt:
def oneTimePad(message, code):
message_out = ""
for i in range(len(message)):
index = (letters.find(message[i]) + letters.find(code[i]))%26
message_out+= letters[index]
return message_out
def otpDecrypt(cipher, key):
message_out = ""
for i in range(len(key)):
index = (letters.find(cipher[i]) - letters.find(key[i]))%26
message_out+= letters[index]
return message_out
the cracker:
def padCracker(m1, m2, guess): # m1, m2 list of nums
m3 = list(map(lambda x, y: (x + y) %26, m1, m2))
check = [] # m3 + guess mod 26
guessNum = list(map(lambda c : letters.find(c), guess))
for i in range(len(m3)-len(guess)+1):
check = list(map(lambda x, y: (x+y)%26, guessNum, m3[i: i+len(guess)]))
print(check, end="")
string = ""
for num in check:
string += letters[num]
print(string)
print(padCracker(m1,m2, "bcd"))
this suggests that c1 starts with "the" and c2 with "and" with key "bcd" but I don't know how to get the rest of the key