forked from nvanheuverzwijn/bchhun_crypto
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbchhun_crypto.py
More file actions
executable file
·66 lines (52 loc) · 1.67 KB
/
bchhun_crypto.py
File metadata and controls
executable file
·66 lines (52 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/python3.2
import os
import sys
import argparse
import re
import math
import unicodedata
import unittest
def decode(value):
output = ""
matches = re.findall("([a-zA-Z]{2})([0-9]+)", value)
for match in matches:
unicode_code_point = math.sqrt(float(match[1]))
output += chr(int(unicode_code_point))
return output
def encode(value):
output = ""
for c in value:
c2 = ord(c)*ord(c)
output += unicodedata.category(chr(c2)) + str(c2)
return output
class QcPyPuzzleTestCase(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test_encode_email(self):
self.assertEqual(
encode("iNfo@quÉbecpythOn.0rg"),
"So11025Mc6084So10404Nl12321Lo4096So12769Lo13689Lo40401So9604Sm10201So9801Cn12544Lo14641Lo13456Sm10816Lo6241So12100Lo2116Mn2304So12996Sm10609"
)
def test_decode_email(self):
self.assertEqual(
decode("So11025Mc6084So10404Nl12321Lo4096So12769Lo13689Lo40401So9604Sm10201So9801Cn12544Lo14641Lo13456Sm10816Lo6241So12100Lo2116Mn2304So12996Sm10609"),
"iNfo@quÉbecpythOn.0rg"
)
if __name__ == "__main__":
unittest.main()
exit()
parser = argparse.ArgumentParser(description="bchhun's crypto")
parser.add_argument("--decode", action="store_true", default=False, help="decode STR")
parser.add_argument("input_string", metavar="STR", type=str, help="the string to decode or encode. Pass '-' to read from stdin.")
args = parser.parse_args()
if args.input_string == "-":
input_string = sys.stdin.readline()
else:
input_string = args.input_string
if args.decode:
output = decode(input_string)
else:
output = encode(input_string)
print(output)