I have a text that is part of a roman. there is a secret message inside this text and I have a given encryption key as below:
Encryption key: 6132342135343721393631633233346221233132
I found the secret message inside the roman as below:
"2zujpggdxdtcergbifcw"
first question is, what kind of key can be this key? and second, how it is possible to find this message and decrypt it?
First of all you need to analyze the input string and the key.
The length of the string is 20 and the length of the key is 40, maybe you can rewrite them to obtain the same length.
Analyzing the key, you can recognize it as hex values of ASCII characters:
key = ['0x61', '0x32', '0x34', '0x21', '0x35', '0x34', '0x37', '0x21', '0x39', '0x36', '0x31', '0x63', '0x32', '0x33', '0x34', '0x62', '0x21', '0x23', '0x31', '0x32']
The input string "2zujpggdxdtcergbifcw" can be written in hex ASCII:
msg = ['0x32', '0x7a', '0x75', '0x6a', '0x70', '0x67', '0x67', '0x64', '0x78', '0x64', '0x74', '0x63', '0x65', '0x72', '0x67', '0x62', '0x69', '0x66', '0x63', '0x77']
Now the input string and the key have the same length, you can try to apply some bitwise operations to decrypt the message.
Trying with the XOR operator, for every element in the list:
secret[i] = msg[i] XOR key[i]
and the result is: "SHAKESPEAREWASHERE", this is a good result but is not very readable.
Since the ASCII is case sensitive, you can try to uppercase the input string "2ZUJPGGDXDTCERGBIFCW" and the result will be: "Shakespeare was here".
There is the code to decrypt the message in python:
#!/usr/bin/env python3
msg = '2ZUJPGGDXDTCERGBIFCW'
key = '6132342135343721393631633233346221233132'
# Creating a list of integers parsing the key string as hex values
key_parts = list(map(lambda x: (int(x,16)), map(''.join, zip(*[iter(key)]*2))))
# Creating a list of integers values of the msg string treated as ascii
msg_parts = list(map(ord, list(msg)))
# Applying the bitwise XOR and convert to char every result
secret_msg = ''.join(map(lambda x: chr(x[0] ^ x[1]), zip(msg_parts, key_parts)))
print(secret_msg) # Prints 'Shakespeare was here'