ROT-0x8000

⊕ 2016-07-06

Often times it’s fun to play with toy crypto puzzles, so for a quick one today I decided to do a quick writeup on my modern take on the ceaser cipher. Taking unicode (UTF-8 specifically) and flip the first bit. This is the same as rotating the alphabet by 0x8000 instead of 13. If you have run into this in any security capture the flag in the last few years than you know who was responsible and who to send hate mail to. It shows the same principles as a normal ROT-13 except for in a modern binary driven world that has a lot of encoding types! In fact it’s simple to apply this to any bit fixed encoding such as UTF-16,UTF-32, etc.

For example the string: ROTx8000 has the interesting side effect of turning all your english letters into chinese characters!‽?! turns into this monstrosity (hope you have a good browser font):

聒聏联聸耸耰耰耰耠聨聡聳耠聴聨聥耠聩聮聴聥聲聥聳聴聩聮聧耠聳聩聤聥耠聥聦聦聥聣聴耠聯聦耠聴聵聲聮聩聮聧耠聡聬聬耠聹聯聵聲耠聥聮聧聬聩聳聨耠聬聥聴聴聥聲聳耠聩聮聴聯耠聣聨聩聮聥聳聥耠聣聨聡聲聡聣聴聥聲聳耡ꀽ耿耡

Taking that same string again and it reverses it back to the original string. This is 100% useless, but I thought it was entertaining. Here is the example code:

#!/bin/env python
import sys

#Rotate by 0x8000 (UTF-8 rot)
def rotx8(s):
    y = ''
    for x in s:
            y += chr(ord(x) ^ 0x8000)
    return y

try:
    print(rotx8(sys.argv[1]))
except:
    print("Cannot rot UTF-8 (rot0x8000 / rot32768) string")

Use it like so: $ python ./rot8.py 'text to encode'