-
Notifications
You must be signed in to change notification settings - Fork 1
/
sip.py
68 lines (64 loc) · 3.76 KB
/
sip.py
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
67
68
"""
Swansea IP Protocol!
Copyright 2022 Alex Blandin
"""
ips = ["127.0.0.1", "255.0.0.1", "137.44.1.20", "48.8.9.72", ".".join(str(x) for x in range(256))]
z_a = ord("z") - ord("a") # apparently I find it hard to remember az is 26 letters
for ip in ips:
sip = []
for byte in ip.split("."):
b, s = int(byte), []
if b < ord("a"):
b += ord("a")
if b > ord("z"):
s.append("Z")
b -= z_a
if b > ord("z"):
z, b = divmod(b, z_a)
s.append(str(z))
s.append(chr(b + ord("a")))
else:
s.append(chr(b))
else:
s.append(chr(b).upper())
sip.append("".join(s))
elif b > ord("z"):
z, b = divmod(b, z_a)
s.append(str(z))
s.append(chr(b + ord("a")))
sip.append("".join(s))
else:
sip.append(chr(b))
print(ip, "=", ".".join(sip))
table = {0: "A", 1: "B", 2: "C", 3: "D", 4: "E", 5: "F", 6: "G", 7: "H",
8: "I", 9: "J", 10: "K", 11: "L", 12: "M", 13: "N", 14: "O", 15: "P",
16: "Q", 17: "R", 18: "S", 19: "T", 20: "U", 21: "V", 22: "W", 23: "X",
24: "Y", 25: "Z", 26: "Zb", 27: "Zc", 28: "Zd", 29: "Ze", 30: "Zf", 31: "Zg",
32: "Zh", 33: "Zi", 34: "Zj", 35: "Zk", 36: "Zl", 37: "Zm", 38: "Zn", 39: "Zo",
40: "Zp", 41: "Zq", 42: "Zr", 43: "Zs", 44: "Zt", 45: "Zu", 46: "Zv", 47: "Zw",
48: "Zx", 49: "Zy", 50: "Zz", 51: "Z4x", 52: "Z4y", 53: "Z5a", 54: "Z5b", 55: "Z5c",
56: "Z5d", 57: "Z5e", 58: "Z5f", 59: "Z5g", 60: "Z5h", 61: "Z5i", 62: "Z5j", 63: "Z5k",
64: "Z5l", 65: "Z5m", 66: "Z5n", 67: "Z5o", 68: "Z5p", 69: "Z5q", 70: "Z5r", 71: "Z5s",
72: "Z5t", 73: "Z5u", 74: "Z5v", 75: "Z5w", 76: "Z5x", 77: "Z5y", 78: "Z6a", 79: "Z6b",
80: "Z6c", 81: "Z6d", 82: "Z6e", 83: "Z6f", 84: "Z6g", 85: "Z6h", 86: "Z6i", 87: "Z6j",
88: "Z6k", 89: "Z6l", 90: "Z6m", 91: "Z6n", 92: "Z6o", 93: "Z6p", 94: "Z6q", 95: "Z6r",
96: "Z6s", 97: "a", 98: "b", 99: "c", 100: "d", 101: "e", 102: "f", 103: "g",
104: "h", 105: "i", 106: "j", 107: "k", 108: "l", 109: "m", 110: "n", 111: "o",
112: "p", 113: "q", 114: "r", 115: "s", 116: "t", 117: "u", 118: "v", 119: "w",
120: "x", 121: "y", 122: "z", 123: "4x", 124: "4y", 125: "5a", 126: "5b", 127: "5c",
128: "5d", 129: "5e", 130: "5f", 131: "5g", 132: "5h", 133: "5i", 134: "5j", 135: "5k",
136: "5l", 137: "5m", 138: "5n", 139: "5o", 140: "5p", 141: "5q", 142: "5r", 143: "5s",
144: "5t", 145: "5u", 146: "5v", 147: "5w", 148: "5x", 149: "5y", 150: "6a", 151: "6b",
152: "6c", 153: "6d", 154: "6e", 155: "6f", 156: "6g", 157: "6h", 158: "6i", 159: "6j",
160: "6k", 161: "6l", 162: "6m", 163: "6n", 164: "6o", 165: "6p", 166: "6q", 167: "6r",
168: "6s", 169: "6t", 170: "6u", 171: "6v", 172: "6w", 173: "6x", 174: "6y", 175: "7a",
176: "7b", 177: "7c", 178: "7d", 179: "7e", 180: "7f", 181: "7g", 182: "7h", 183: "7i",
184: "7j", 185: "7k", 186: "7l", 187: "7m", 188: "7n", 189: "7o", 190: "7p", 191: "7q",
192: "7r", 193: "7s", 194: "7t", 195: "7u", 196: "7v", 197: "7w", 198: "7x", 199: "7y",
200: "8a", 201: "8b", 202: "8c", 203: "8d", 204: "8e", 205: "8f", 206: "8g", 207: "8h",
208: "8i", 209: "8j", 210: "8k", 211: "8l", 212: "8m", 213: "8n", 214: "8o", 215: "8p",
216: "8q", 217: "8r", 218: "8s", 219: "8t", 220: "8u", 221: "8v", 222: "8w", 223: "8x",
224: "8y", 225: "9a", 226: "9b", 227: "9c", 228: "9d", 229: "9e", 230: "9f", 231: "9g",
232: "9h", 233: "9i", 234: "9j", 235: "9k", 236: "9l", 237: "9m", 238: "9n", 239: "9o",
240: "9p", 241: "9q", 242: "9r", 243: "9s", 244: "9t", 245: "9u", 246: "9v", 247: "9w",
248: "9x", 249: "9y", 250: "10a", 251: "10b", 252: "10c", 253: "10d", 254: "10e", 255: "10f"} # yapf: disable