Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 26th, 2006, 8:30 PM   #1
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 1,888
Rep Power: 5 Sane will become famous soon enough
Send a message via MSN to Sane
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)
Sane is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:18 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC