import random encrypt_table={} def generate_table(): plain_list=[] random_list=[] for i in range(65,91): #all of ascii plain_list+=[chr(i)] #creating ascii chars and adding to plain_string random_list=plain_list[:] #copy of list so that we can make a separate shuffled version random.shuffle(random_list) #shuffle list for i in range(0, len(plain_list)): #iterate over each letter in the alphabetical list encrypt_table[plain_list[i]]=random_list[i] #index assign from each list in order return encrypt_table def reverse_table(encrypt_table): for x in encrypt_table: #iterate through each set of translation table entries reverse_table[encrypt_table[x]]=x #reverse table keys will equal the values of encrypt table return reverse_table def string_to_table(table_string): s_list=list(table_string) #splits the string into list items return list_table def table_to_string(table): for i in table: stringoftable+=str(table[i]) #inserting values in the table as concatenated strings, one by one return stringoftable table=generate_table() string=table_to_string(table) def encrypt(table, string):
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question