Perse Studio

Independent-learning super-curriculum projects: reading, research and ideas shared by Perse students

Encoder

Kamran B, Year 8

I wrote this Python code because I wanted to create a program to convert to and from a made up language. It allows you to communicate with your friends in secret. A further improvement would be to make the language more random instead of 01~ = a, 02~ = b, etc.

 

# Python program code

#Encoder

 

translate = {kb-1

“A” : “01~”,

“a” : “02~”,

“B” : “03~”,

“b” : “04~”,

“C” : “05~”,

“c” : “06~”,

“D” : “07~”,

“d” : “08~”,

“E” : “09~”,

“e” : “10~”,kb-2

“F” : “11~”,

“f” : “12~”,

“G” : “13~”,

“g” : “14~”,

“H” : “15~”,

“h” : “16~”,

“I” : “17~”,

“i” : “18~”,

“J” : “19~”,

“j” : “20~”,kb-3-v-2

“K” : “21~”,

“k” : “22~”,

“L” : “23~”,

“l” : “24~”,

“M” : “25~”,

“m” : “26~”,

“N” : “27~”,

“n” : “28~”,

“O” : “29~”,

“o” : “30~”,

“P” : “31~”,kb-4

“p” : “32~”,

“Q” : “33~”,

“q” : “34~”,

“R” : “35~”,

“r” : “36~”,

“S” : “37~”,

“s” : “38~”,

“T” : “39~”,

“t” : “40~”,

“U” : “41~”,

“u” : “42~”,

“V” : “43~”,

“v” : “44~”,

“W” : “45~”,

“w” : “46~”,

“X” : “47~”,

“x” : “48~”,

“Y” : “49~”,

“y” : “50~”,

“Z” : “51~”,

“z” : “52~”,

” ” : “53~”,

“!” : “54~”,

“.” : “55~”,

“,” : “56~”,

“@” : “57~”,

“0” : “58~”,

“1” : “59~”,

“2” : “60~”,

“3” : “61~”,

“4” : “62~”,

“5” : “63~”,

“6” : “64~”,

“7” : “65~”,

“8” : “66~”,

“9” : “67~”,

}

 

text = str(input(“Input some text to encode.”))

 

for c in text:

  print(translate[c],end=””)

print()

 

#Decoder

 

untranslate = dict(zip(translate.values(),translate.keys()))

 

text = str(input(“Input some code to decode.”))

for i in range(0,len(text)-2,3):

  print(untranslate[text[i:i+3]],end=””)

print()

 

 

 

Comments are closed.