encryption/decryption code

Put your programming skills to the test in these challenges.

encryption/decryption code

Post by zen3001 on Sat Dec 16, 2017 2:33 pm
([msg=95071]see encryption/decryption code[/msg])

SPOILER
so I wrote a little code in python to decrypt the encrypted password in level 6 from the basic missions, just wanted to share it here...
sry if you don't like reading unclean codes, I'm still an amateur so there's probably something ugly I could't notice
Code: Select all
>>> def encrypt(st):
...     st2 = str(st)
...     ls = []
...     st3 = ''
...     for i in st2:
...             ls.append(i)
...     for i in ls:
...             st3 = st3+chr(ord(i)+ls.index(i))
...     print('original value: '+st2)
...     print('converted/encrypted value: '+st3)
...
>>> encrypt('hello')
original value: hello
converted/encrypted value: hfnns
>>> def decrypt(st):
...     st2 = str(st)
...     ls = []
...     st3 = ''
...     for i in st2:
...             ls.append(i)
...     for i in ls:
...             st3 = st3+chr(ord(i)-ls.index(i))
...     print('encrypted value: '+st2)
...     print('converted/decrypted value: '+st3)
...
>>> decrypt('hfnns')
encrypted value: hfnns
converted/decrypted value: hello


-- Sun Dec 31, 2017 8:45 pm --

this code sucks when you have a character multiple times in a word
here's a better code
Code: Select all
>>> def encrypt(x):
   f = ""
   l = list(str(x))
   for i in range(len(l)):
      f = f+chr(ord(l[i])+i)
   return f

>>> encrypt("hello")
'hfnos'
>>> def decrypt(x):
   f = ""
   l = list(str(x))
   for i in range(len(l)):
      f = f+chr(ord(l[i])-i)
   return f

>>> decrypt("hfnos")
'hello'
zen3001
New User
New User
 
Posts: 5
Joined: Wed Dec 06, 2017 2:14 pm
Blog: View Blog (0)


Return to Programming

Who is online

Users browsing this forum: No registered users and 0 guests