| Sane |
Mar 26th, 2006 9:30 PM |
Factorial Encryption
Another play on Python out of boredom. I doubt this could be a serious encryption, as it wasn't very thought out. But I still believe it's extremely strong and could withstand anyone's attempts unless they are a professional. Which means I did my job.
If you can prove me wrong, please do so. I love to learn.
Here it is with a brief systematic explanation along with the source. Very short amount of code, but highly effective. :)
:
info = """
Factorial Encryption
March 26, 2006
Copyright by Aaron Voelker, Saney
------------------------------------------------------
Create a checksum from a literal using
a modified factorial function.
------------------------------------------------------
Basic encryption is intended to work as SHA-1 or Md5
checksum encryptions do.
The difference: throw in an optional password argument
plus salt, and any cracker should be left with nowhere
to start.
------------------------------------------------------
1 - Make an array of characters a-z + 0-9 + A-Z.
2 - If a password is present, move letters from
password to front of array.
3 - Add array to the front of string to encrypt.
4 - Get ordinal value of each character in string.
5 - Throw each character in an avalanche style
through the modified factorial function.
6 - Calculate a 'sum' of all the results multiplayed
by the index at which they were created.
7 - Index the charset by the result of each
factorial, multiplayed by the index, subtracted
by the 'sum'.
8 - Return 'clength' number of letters based on index
determined by 'sum'%(length of string-'clength')
plus the length of 'clength'.
"""
def factorial(x, limit=1, inc=1):
if x <= limit:
return limit
return x + factorial(x-limit)
def get_fs(ords, lenx):
sum = 0
fs = []
# [LABEL 5]
for i in range(lenx):
f = factorial(ords[i],-ords[(i+1)%lenx],ords[(i+2)%lenx]/10)
# [LABEL 6]
sum += f*(i+1)
fs += [f]
return fs, sum
def mk_charset(ps = ''):
# [LABEL 1]
set = [chr(x) for x in range(97, 123) + range(48, 58) + range(65, 91)]
# [LABEL 2]
for l in ps:
try:
set.remove(l)
set = [l] + set
except ValueError:
pass
return set
def fencrypt(x, passw=''):
clength = 25
charset = mk_charset(passw)
charrng = len(charset)
# [LABEL 3]
newx = x + ''.join(charset)
lenx = len(newx)
# [LABEL 4]
ords = [ord(l) for l in list(newx)]
fs, sum = get_fs(ords, lenx)
# [LABEL 7]
res = ''.join( charset[ (fs[f]*(f+1)-sum)%charrng ] for f in range(lenx) )
# [LABEL 8]
start = sum%(lenx-clength)
return res[ start:start+clength ]
if __name__ == '__main__':
print fencrypt(info)
|