Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Encoding:
- [code py]
- chars = ['', '', '', '', '', '', '', '', '', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '.', ' ', '_']
- def encode (val):
- letternum = 1
- val = str(val)
- encoded = ""
- for i in range (1, len(str(val))):
- encoded = str(encoded) + str(chars.index(val[letternum-1]))
- letternum += 1
- return int(encoded + "00")
- print(encode(input("Enter a word: ")))
- [/code]
- Decoding:
- [code py]
- chars = ['', '', '', '', '', '', '', '', '', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '.', ' ', '_']
- def decode (val):
- letternum = 1
- value = ""
- idx = None
- while True:
- val = str(val)
- idx = val[letternum-1] + val[letternum]
- letternum += 2
- if int(idx) < 1:
- break
- value = value + chars[int(idx) - 1]
- return value
- print(decode(input("Enter an encoded value: ")))
- [/code]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement