# Hacking

ord() 是将字符转换为了对应的 ASCII 值，chr() 将对应的值转换为字符，例如：

>>> ord("A")
65
>>> chr(65)
'A'

>>> chr(ord("A")+3)
'D'
>>> chr(ord("B")+3)
'E'
>>> chr(ord("C")+3)
'F'
...
>>> chr(ord("W")+3)
'Z'

>>> chr(ord("X")+3)
'['

>>> 4%8
4
>>> 5%8
5
>>> 8%8
0
>>> 9%8
1

>>> ord("X")-ord("A")
23
>>> ord("X")-ord("A") +3
26
>>> (ord("X")-ord("A") +3)%26
0
>>> (ord("X")-ord("A") +3)%26 + ord("A")
65
>>> chr((ord("X")-ord("A") +3)%26 + ord("A"))
'A'

def encrypt(char, key=3):
"""
加密
"""
return chr((ord(char) - ord("A") + key) % 26 + ord("A"))

def decrypt(char, key=3):
"""
解密
"""
return chr((ord(char) - ord("A") - key) % 26 + ord("A"))

plain = "ZENOFPYTHON"
cipher = "".join([encrypt(c) for c in plain])
print(cipher)
>>>CHQRISBWKRQ  # 密文

plain = "".join([decrypt(c) for c in cipher])
print(plain)
>>>ZENOFPYTHON # 明文

def encrypt(char, key=3):

if not char.isalpha():
return char
else:
a = "A" if char.isupper() else "a"
return chr((ord(char) - ord(a) + key) % 26 + ord(a))

def decrypt(char, key=3):
if not char.isalpha():
return char
else:
a = "A" if char.isupper() else "a"
return chr((ord(char) - ord(a) - key) % 26 + ord(a))

plain = """Ftq Lqz ar Bkftaz, nk Fuy Bqfqde
Nqmgfurgx ue nqffqd ftmz gsxk.
Qjbxuouf ue nqffqd ftmz uybxuouf.
Euybxq ue nqffqd ftmz oaybxqj.
Oaybxqj ue nqffqd ftmz oaybxuomfqp.
Rxmf ue nqffqd ftmz zqefqp.
Ebmdeq ue nqffqd ftmz pqzeq.
Dqmpmnuxufk oagzfe.
Ebqoumx omeqe mdqz'f ebqoumx qzagst fa ndqmw ftq dgxqe.
Mxftagst bdmofuomxufk nqmfe bgdufk.
Gzxqee qjbxuoufxk euxqzoqp.
Uz ftq rmoq ar mynusgufk, dqrgeq ftq fqybfmfuaz fa sgqee.
Ftqdq etagxp nq azq-- mzp bdqrqdmnxk azxk azq --anhuage imk fa pa uf.
Mxftagst ftmf imk ymk zaf nq anhuage mf rudef gzxqee kag'dq Pgfot.
Zai ue nqffqd ftmz zqhqd.
Mxftagst zqhqd ue arfqz nqffqd ftmz *dustf* zai.
Ur ftq uybxqyqzfmfuaz ue tmdp fa qjbxmuz, uf'e m nmp upqm.
Ur ftq uybxqyqzfmfuaz ue qmek fa qjbxmuz, uf ymk nq m saap upqm.
Zmyqebmoqe mdq azq tazwuzs sdqmf upqm -- xqf'e pa yadq ar ftaeq!

BkOaz Otuzm Nquvuzs Dqpqqy Oapq ue: ???
"""

PS：北京站本月14号举行，深圳站本月27号举行，报名地址戳阅读原文。本游戏解释权归我所有

• 0
点赞
• 0
评论
• 0
收藏
• 一键三连
• 扫一扫，分享海报

01-17 1003
12-05
04-09
02-03 1142
11-13 2万+
12-21 3016
08-24 444
07-19 11万+
01-12 4852
12-10 1万+