When I started CTF, a Caesar cipher came out, so decryption processing was necessary. You can do it manually, but this is a program! It can also be a rehabilitation! So I wrote it immediately. My machine only had a Python development environment, so go with Python!
In order to decrypt it, you need to know what algorithm the cipher was generated by. The Caesar cipher is generated by shifting characters by 3 characters. How simple!
First of all, encryption. Shifts plaintext character by character with the specified key (number). Since the case is different, this time we will use only lowercase letters. There are 25 English letters, so be careful to turn around. Encrypt the appropriate character string "wjrslairznb"!
def crypt(plainStr, shiftInt):
resultStr = ""
for char in plainStr:
if ord(char) + shiftInt > ord('z'):
resultStr = resultStr + chr(ord(char) + shiftInt - 26)
else:
resultStr = resultStr + chr(ord(char) + shiftInt)
print('crypt:' + resultStr)
Execution result
Decryption was simply calculated in reverse ...
def decrypt(cryptoStr, shiftInt):
resultStr = ""
for char in cryptoStr:
if ord(char) - shiftInt < ord('a'):
resultStr = resultStr + chr(ord(char) - shiftInt + 26)
else:
resultStr = resultStr + chr(ord(char) - shiftInt)
print('decrypt:' + resultStr)
Execution result It seems to be easier and simpler ...
Not available. Vulnerable! !! It is a code made in ancient Rome, so it must have been valid in the past. Cryptography has a history.
Actually, it's been a while since I've had a program, and even though I have a Python environment, I haven't touched it and it was a lot of fun. There are tons of programs like this out there if you google, but I like to write them myself first and then look at the genius code and match the answers later.
Recommended Posts