I spent some of my time today creating an encryption algorithm. It isn't very good and not really secure but I created it just as a learning exercise. I'm sure something like this has been done before, but either way, I enjoyed making it.
It basically just adds the ascii values of a key character and a plaintext character and returns the resluting sum represented as an ascii character.
It works best on only human-readable strings and is quite slow so, it's not really useful, but as I said, it was just a learning exercise out of boredom. I guess you could use it for obfuscation of simple strings, though.
Any feedback is welcome!
Here is the code (The indentation is messed up; I tried fixing it, but it wouldn't work):
Here is the pastebin link:
http://pastebin.com/nNtDSaqa
Examples:
Thanks for reading! 😁
It basically just adds the ascii values of a key character and a plaintext character and returns the resluting sum represented as an ascii character.
It works best on only human-readable strings and is quite slow so, it's not really useful, but as I said, it was just a learning exercise out of boredom. I guess you could use it for obfuscation of simple strings, though.
Any feedback is welcome!
Here is the code (The indentation is messed up; I tried fixing it, but it wouldn't work):
Code
#!/usr/bin/env python
# IntroCrypt
# Coded by: Introvert
import random
import string
from itertools import izip
class Encrypt(object):
def __init__(self, plaintext, key):
self.plaintext = plaintext
self.key = key
def encrypt(self):
plaintext = list(str(self.plaintext))
key = list(str(self.key))
if len(key) != len(plaintext):
print "The key size must be the same as the plaintext."
return
else:
try:
ciphertext = []
for plaintext_chr, key_chr in izip(plaintext, key):
ciphertext.append(chr(((ord(plaintext_chr) + ord(key_chr)) % 127)))
return ''.join(ciphertext)
except:
print "An encryption error has occured!"
return
class Decrypt(object):
def __init__(self, ciphertext, key):
self.ciphertext = ciphertext
self.key = key
def decrypt(self):
ciphertext = list(str(self.ciphertext))
key = list(str(self.key))
if len(key) != len(ciphertext):
print "The key size must be the same as the ciphertext."
return
else:
try:
plaintext = []
for ciphertext_chr, key_chr in izip(ciphertext, key):
plaintext.append(chr(((ord(ciphertext_chr) - ord(key_chr)) % 127)))
return ''.join(plaintext)
except:
print "A decryption error has occured!"
return
def gen_key(key_size, chars=string.ascii_uppercase + string.ascii_lowercase + string.digits):
return ''.join(random.SystemRandom().choice(chars) for x in range(key_size))Here is the pastebin link:
http://pastebin.com/nNtDSaqa
Examples:
Code
KEY: kROisbTxoj
PLAIN: abcdefghij
ENCRYPTED: M53NYI<aYUCode
KEY: 3cdqbAqvWAaC
PLAIN: Hello World!
ENCRYPTED: {IQ^RaIfJ.FdThanks for reading! 😁


