Skip to content

Instantly share code, notes, and snippets.

@alswl
Last active November 22, 2017 10:07
Show Gist options
  • Save alswl/7bd9b819e0db4146eef68f7bba6da1f6 to your computer and use it in GitHub Desktop.
Save alswl/7bd9b819e0db4146eef68f7bba6da1f6 to your computer and use it in GitHub Desktop.
大吉大利,晚上吃鸡
# echo "V2loYWx1bm9mdW5jaWhtISBTaW8gYWluIGNuISBXZnVjZyBzaW9sIGpsY3R5IHFjbmIgc2lvbCB1ZmFpbGNuYmc6IDU5NTkyMjY4LiBCaWp5IGNuIGNtIGhpbiB4aWh5IHZzIGJ1aHguIE5idW4gY20gcWJzIHF5IGJ1cHkgd2lnam9ueWxtIHVoeCBVQy4gSGlxIG9teSBuYnkgZXlzIG5pIHV3d3ltbSBCQ0ZGIFVDIG15bHBjd3k6IHh5dnV5eTR1enp2eXV2dTkwOXUxODQwNjY5ODF4NTV1Lg==" | base64 -D
raw = 'Wihalunofuncihm! Sio ain cn! Wfucg siol jlcty qcnb siol ufailcnbg: 59592268. Bijy cn cm hin xihy vs buhx. Nbun cm qbs qy bupy wigjonylm uhx UC. Hiq omy nby eys ni uwwymm BCFF UC mylpcwy: xyvuyy4uzzvyuvu909u184066981x55u.'
for i in raw:
if i >= 'a' and i <= 'z':
print(chr((ord(i) + 6 - ord('a')) % 26 + ord('a')), end='')
elif i >= 'A' and i <= 'Z':
print(chr((ord(i) + 6 - ord('A')) % 26 + ord('A')), end='')
else:
print(i, end='')
@lyricat
Copy link

lyricat commented Nov 22, 2017

import base64
def trans(x, shift):
    ox = ord(x)
    ret = ox
    rngs = [
        {"start": ord('a'), "end": ord('z'), "pad": 97},
        {"start": ord('A'), "end": ord('Z'), "pad": 65},
    ]
    for rng in rngs:
        pcp = rng['end'] - rng['start'] + 1
        if rng["start"] <= ox and rng["end"] >= ox:
            ret = (ox - rng["pad"] + shift) % pcp + rng["pad"]
        else:
            pass
    return chr(ret)

def encode(src):
    xx = ''.join([trans(x, -6) for x in src])
    xx = base64.b64encode(bytes(xx, 'UTF-8')).decode('UTF-8')
    return xx

def decode(src):
    xx = base64.b64decode(bytes(src, 'UTF-8')).decode('UTF-8')
    xx = ''.join([trans(x, 6) for x in xx])
    return xx
    
ess = encode(src)
print('Encoded:', ess)
print('Decoded:', decode(ess))
print('Trans: a ->', trans('a', 6) )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment