This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Simple String Encryption
1) reverse encryption
def encryptstring(strhere):
    chars = str.lower('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789')
    chars_r = chars[::-1]
    tmp_str = ''
    for i in range(len(strhere)):
      pos = chars.find(strhere[i])
      tmp_str += chars_r[int(pos)]
    return tmp_str
print (encryptstring('hello'))
2)Vigenere cipher

import base64
class Vigenere_cipher():
    def __init__(self, e_key):
        self._ekey = e_key
    def encrypt(self,clear_text):
        enc = []
        for i in range(len(clear_text)):
            key_c = self._ekey[i % len(self._ekey)]
            enc_c = chr((ord(clear_text[i]) + ord(key_c)) % 256)
        return base64.urlsafe_b64encode("".join(enc))  
    def decrypt(self,enc_text):
        dec = []
        enc_text = base64.urlsafe_b64decode(enc_text)
        for i in range(len(enc_text)):
            key_c = self._ekey[i % len(self._ekey)]
            dec_c = chr((256 + ord(enc_text[i]) - ord(key_c)) % 256)
        return "".join(dec) 

person1 = Vigenere_cipher("john")  
3) rot 13
def rot13(s):
    result = "" 
    for v in s: 
        c = ord(v) 
        if c >= ord('a') and c <= ord('z'):
            if c > ord('m'):
                c -= 13
                c += 13
        elif c >= ord('A') and c <= ord('Z'):
            if c > ord('M'):
                c -= 13
                c += 13 
        result += chr(c) 
    return result
Disclaimer: Don't be misguided looking at my usergroup and assume whatever I say is official. When I speak in community I am just a member with personal opinions.

Forum Jump:

Users browsing this thread: 1 Guest(s)