-2

so what I have currently set up is an import from a txt file. this is just a 94 character string which contains all the typeable characters (except whitespace). I want to use this as a new alphabet for some encryption.

for instance someone uses "user12AB#BAuser" as a password. the key would then convert this using the key. for instance, lowercase U is the 21st letter in the alphabet. this will then be assigned to the 21st letter in the key.

How would you code this?

the coding language is python.

thanks for your assistance.

James
  • 3
  • 3
  • What's your question? Please [edit] to clarify. BTW welcome to SO! Check out the [tour] and [ask]. – wjandrea Apr 30 '20 at 21:58
  • I think [this answer](https://stackoverflow.com/a/3269756/1679849) tells you pretty much everything you need to know. Read up on the [`string.translate()`](https://www.programiz.com/python-programming/methods/string/translate) function if you need more information. Also, please bear in mind that storing encrypted passwords is rarely a good idea, especially with such a weak encryption method. Use a password hashing method such as bcrypt instead. – r3mainer Apr 30 '20 at 22:18
  • You need to post something on what you have attempted up till now while working on your question. https://stackoverflow.com/help/how-to-ask – Slartibartfast May 01 '20 at 02:13

1 Answers1

1

The easiest way would be to create a Dictionary, set the text as a key and the text with some offset as the value

string = "abcdefghijklmnopqrstuvwxyz"
offset = 5
dictionary = {}
for i in range(len(string)):
    dictionary[string[i]] = string[(i+offset)%len(string)] 

Then to encode your message you can index the dictionary

message = "hello"
code = ""

for m in message:
    code+=dictionary[m]

print(code)

Output = mjqqt

Jay
  • 2,553
  • 3
  • 17
  • 37