Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: UTF-8 -*-
- #Encrypter by BrolofTheViking
- #4/23/12
- #Cipher
- from random import randint
- #This function takes an input string and integer and outputs an encrypted string.
- #Each character in the input string will be turned into multiple characters. The number of characters it turns into is equal to the input integer.
- #Each character has a numerical value associated with it
- #The value of each character in the group of characters in the encrypted string that corresponds to each character in the input string adds up to the value of the character in the input string.
- #For example, the character Z has a value of 13
- #So if the input string is just "Z" and the input integer is 3, then "Z" might be represented as "gkX" because the value of g is 2, the value of k is 10, and the value of X is 1
- #The encryption also puts random numbers into the output, all of which are treated as having a value of 0
- #So "Z" can also be represented as "8Z2"
- #Or as "X2*" because * has a value of 12, and X has a value of 1
- #The encrypter adds the
- global default
- default = 2
- def encrypt(string,encryptvalue = default):
- if type(string) != str:
- string = str(string)
- if encryptvalue < 2:
- encryptvalue = 2
- alphabet = ['Fill','X','g','h','b','#','v','d',']','`','k','q','*','Z','D','j','p','J','W','i','T','c','%','s','!','[','Q','_','R','A','C',"'",'$','P','.',')','l','Y','f','y','n','S',' ','O','}','&','^','K','B','e','|','?','@','a','(','>',':','z','<','u','t','=','N','"','F','H',';',',','U','m','I','r','-','G','{','M','E','+','o','~','V','w','/','x','L','1','2','3','4','5','6','7','8','9','0']
- encryptedstring = ""
- if encryptvalue != default:
- encryptedstring += str(encryptvalue)
- encryptedstring += alphabet[randint(1,82)]
- n = 0
- while n < len(string):
- charactervalue = 0
- addvalue = 0
- characteradded = 0
- while string[n] != alphabet[charactervalue]:
- charactervalue += 1
- if charactervalue >= 85:
- firstcharacter = True
- while characteradded < encryptvalue - 1:
- if firstcharacter == True:
- random = randint(10,84)
- firstcharacter = False
- else:
- random = randint(0,charactervalue-addvalue)
- if random == 0:
- encryptedstring += str(randint(0,9))
- else:
- encryptedstring += alphabet[random]
- addvalue += random
- characteradded += 1
- else:
- while characteradded < encryptvalue - 1:
- random = randint(0,charactervalue-addvalue)
- if random == 0:
- encryptedstring += str(randint(0,9))
- else:
- encryptedstring += alphabet[random]
- addvalue += random
- characteradded += 1
- random = charactervalue-addvalue
- if random == 0:
- encryptedstring += str(randint(0,9))
- else:
- encryptedstring += alphabet[random]
- addvalue += random
- n += 1
- return encryptedstring
- def decrypt(string):
- alphabet = ['Fill','X','g','h','b','#','v','d',']','`','k','q','*','Z','D','j','p','J','W','i','T','c','%','s','!','[','Q','_','R','A','C',"'",'$','P','.',')','l','Y','f','y','n','S',' ','O','}','&','^','K','B','e','|','?','@','a','(','>',':','z','<','u','t','=','N','"','F','H',';',',','U','m','I','r','-','G','{','M','E','+','o','~','V','w','/','x','L','1','2','3','4','5','6','7','8','9','0']
- set_size = 0
- start = 0
- while string[start] == "0" or string[start] == "1" or string[start] == "2" or string[start] == "3" or string[start] == "4" or string[start] == "5" or string[start] == "6" or string[start] == "7" or string[start] == "8" or string[start] == "9":
- start += 1
- if start == 0:
- set_size = default
- else:
- set_size = int(string[:start])
- start += 1
- end = start + set_size
- output = ""
- while start < len(string):
- character = 0
- while start < end:
- charactervalue = 0
- if string[start] == "0" or string[start] == "1" or string[start] == "2" or string[start] == "3" or string[start] == "4" or string[start] == "5" or string[start] == "6" or string[start] == "7" or string[start] == "8" or string[start] == "9":
- charactervalue = 0
- else:
- while string[start] != alphabet[charactervalue]:
- charactervalue += 1
- character += charactervalue
- start += 1
- output += alphabet[character]
- end += set_size
- return output
Advertisement
Add Comment
Please, Sign In to add comment