ROT47 is a Caesar cipher rotated by 47 chars. It takes the ASCII characters between 33 and 126 and then moving them on 47 times. It is easy to reverse the cipher, by just performing the same operation.
ROT47 |
Example
A basic mapping is:
Plain: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890!.:,;' Cipher: 23456789:;<=>?@ABCDEFGHIJKpqrstuvwxyz{|}~!"#$%&'()*+ `abcdefgh_P]i[jVEncrypted Cipher: Decrypted Cipher:
The coding is:
import sys def rot47(s): x = [] for i in range(len(s)): j = ord(s[i]) if j >= 33 and j <= 126: x.append(chr(33 + ((j + 14) % 94))) else: x.append(s[i]) return ''.join(x) cipher="hello" if (len(sys.argv)>1): cipher=str(sys.argv[1]) res=rot47(cipher) print ("Encrypted Cipher: {}\nDecrypted Cipher: {}".format(cipher,res ))
A sample run is:
Encrypted Cipher: %6DE:?8 `ab Decrypted Cipher: Testing 123
And code: