Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

My (Pure Python) Custom Encryption Algorithm.

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):
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<aYU
Code
KEY: 3cdqbAqvWAaC
PLAIN: Hello World!
ENCRYPTED: {IQ^RaIfJ.Fd

Thanks for reading! 😁
Very cool dude, thanks for sharing this. 👍

You should try making a cipher too, see how that goes. ✌
.-=~
(Jun 17, 2015 09:55 PM)TheDubWubCub Wrote:  Very cool dude, thanks for sharing this. 👍

You should try making a cipher too, see how that goes. ✌

Thanks for the kind words. I really appreciate it.

On a side note, is this not already some sort of cipher? As far as I'm aware a cipher is the actual encryption algorithm part. So this is it:
Code
chr(((ord(plaintext_chr) + ord(key_chr)) % 127)))

Anyway, thanks again for the kind words! 😁
This is really nifty actually. You should try to make another, more improved one.
(Jun 17, 2015 11:58 PM)帖子作者 Wrote:  This is really nifty actually. You should try to make another, more improved one.

Thanks! I was actually thinking of making another, improved version. I'll see what I can do, I know that I definitely want to improve the speed, so that will probably be my first improvement.

Thanks for the reply 😁
(Jun 17, 2015 11:57 PM)Introvert Wrote:  Thanks for the kind words. I really appreciate it.

On a side note, is this not already some sort of cipher? As far as I'm aware a cipher is the actual encryption algorithm part. So this is it:
Code
chr(((ord(plaintext_chr) + ord(key_chr)) % 127)))

Anyway, thanks again for the kind words! 😁

Yea no problem. :]

I'd consider this as an encryption algorithm, a beginner one, but it wouldn't traditionally be recognized as a cipher since it uses a password.

Check out this thread for more info if you want. ✌
https://hackforums.net/showthread.php?tid=4562087

This also helps clarify some terms: 🎉
http://www.brighthub.com/computing/enter...65254.aspx

Thanks again for your post & I look forward towards your future ones. 👍
.-=~
(Jun 18, 2015 08:21 AM)TheDubWubCub Wrote:  Yea no problem. :]

I'd consider this as an encryption algorithm, a beginner one, but it wouldn't traditionally be recognized as a cipher since it uses a password.

Check out this thread for more info if you want. ✌
https://hackforums.net/showthread.php?tid=4562087

This also helps clarify some terms: 🎉
http://www.brighthub.com/computing/enter...65254.aspx

Thanks again for your post & I look forward towards your future ones. 👍

Aah, ok. I get it. Thanks!
What about decription
It won't be that cool since you're using %
And why 127 exactly
(Jun 19, 2015 08:59 AM)Bad C0d3 Wrote:  What about decription
It won't be that cool since you're using %
And why 127 exactly

Decryption is in the code. It works prefectly fine. Instead of plus I just use a minus which reverses the operation. It is 127, because that is the amount of standard ascii values (does not include the extended ascii table).


Possibly Related Threads...
Thread / Author Replies Views Last Post
by IntrovertJul 8, 2015 07:18 AM 11 312 Jul 8, 2015 07:18 AM
Last Post: Introvert
by Black ScorpionMay 27, 2015 04:57 PM 12 248 May 27, 2015 04:57 PM
Last Post: Black Scorpion