# What are the vulnerabilities of this homemade encryption algorithm? [closed]

I decided to program a relatively trivial encryption algorithm in my downtime. This algorithm takes a seed from a user (supports floating point seeds), and then adds 1 to the seed for every iteration of each character of a message, performing a bitwise xor with a pseudorandomly generated value. As Python uses Mersenne twister, a non-cryptographic pseudorandom generator, I figured that this encryption algorithm must have some vulnerabilities, as Mersenne twister is not cryptographically secure.

To name a few:

1. Can an encrypted message be plaintext attacked like a regular low byte key XOR encryption?

2. Can an attacker guess the value of the seed based upon patterns in the encrypted message?

3. Can multiple inputted seeds end up with the same encrypted message?

import random
import codecs
import binascii
import math
def encrypt(x):
y = float(input("Enter the encryption key  -->"))
random.seed(y)
i = 0
x = list(x)
while i < len(x):
y += 1
rand = random.randint(1,random.randint(200,400))
random.seed(rand)
x[i] = chr(ord(x[i]) ^ rand ^ abs((~int(rand/2))))
i += 1
x = "".join(x)
x = str(binascii.hexlify(x.encode("utf-8")))
x = list(x)
x.pop(x.index("'"));x.pop(x.index("b"));x.pop(x.index("'"))
return "".join(x)
def decrypt(x):
x = bytes.fromhex(x).decode('utf-8')
y = float(input("Enter the decryption key -->"))
random.seed(y)
i = 0
x = list(x)
while i < len(x):
y += 1
rand = random.randint(1,random.randint(200,400))
random.seed(rand)
x[i] = chr(ord(x[i]) ^ rand ^ abs((~int(rand/2))))
i += 1
x = "".join(x)
return x
def instructions():
print("Welcome to the RBES3 (Randomized Bitwise Encryption Standard 3) symmetric key encryption program.")
print("Choose to either decrypt or encrypt your string in this program. \n")
def main():
x = input("Would you like decrypt encrypt a string? (d for decrypt, e for encrypt) -->")
if x == "d":
args = input("Would you like to decrypt a string or a file? (s/f) -->").lower()
if args == "f":
filename = input("Enter the path to the file that you want to decrypt. -->")
file = open(filename,"r+")
dcrypt = open("_"+filename[-(len(filename)//3+1)::]+"_decrypted", "w")
try:
print("The decrypted string is --> "+done)
dcrypt.write(done)
file.close()
except:
print("\nOne or more of your parameters were invalid.  Please check your input and try again.  If you are using an ASCII encoding, check your key, as ASCII does not support special characters.")
if args == "s":
string = input("Enter a string to be decrypted here. -->")
try:
print("The decrypted string is --> "+decrypt(string))
except:
if x == "e":
args = input("Would you like to encrypt a string or a file? (s/f) -->").lower()
if args == "f":
filename = input("Enter the path to the file that you want to encrypt. -->")
file = open(filename,"r+")
ecrypt = open("_"+filename[-(len(filename)//3+1)::]+"_encrypted", "w")
try:
print("The decrypted string is --> "+done)
ecrypt.write(done)
file.close()
except:
if args == "s":
string = input("Enter a string to be encrypted here. -->")
try:
print("The encrypted string is --> "+encrypt(string))
except:
main()


Examples:

    "This is a test message" (no quotes)
seed = 29

-

## migration rejected from security.stackexchange.comMay 5 '15 at 7:07

This question came from our site for information security professionals. Votes, comments, and answers are locked due to the question being closed here, but it may be eligible for editing and reopening on the site where it originated.

## closed as off-topic by CodesInChaos♦, poncho, yyyyyyy, Reid, cygnusvMay 5 '15 at 7:07

• This question does not appear to be about cryptography within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

Vulnerability #1 - you're rolling your own crypto. – Iszi Apr 1 '15 at 4:20
@lszi I suspect the author already knows that. And that's a cause of vulnerabilities, but it's not actually a vulnerability. – immibis Apr 1 '15 at 7:53
I'm voting to close this question as off-topic because it's about breaking a homebrew cipher. – CodesInChaos May 4 '15 at 14:32