1. Re: Data Encryption

At 10:15 PM 6/18/98 -0400, you wrote:

>Robert B Pilkington wrote (a month ago):
>
>I have made one (an algorithm) that uses password encryption. I
>figure that if you use several passwords, and decrypt with the WRONG
>password at least once, the file would be impossible to crack, especially=
>
>if I make a couple of changes to the basic algorithm. It's fast too.
>
>This is how mine works:
>
>It gets and confirms the password
>It performs calculations on the password (adding the ASCII values up and
>such and a little bit more) to get a number.
>Seeds the randomizer to the number (set_rand(number))
>Takes each character in the file, and adds a random number between 1 and
>255 to it and puts it into the output file. (or subtracts in decryption)
>
>I think I can learn some low-level concepts from this algorithm.
>
>Are you using ASCII values or bits?  There are eight bits in a byte.  So =
>if
>you add 1 to 255 to eight bits, you got a 9-bit number.  How can you writ=
>e
>byte-for-byte?  Similar thing for ASCII values.
>
>--Alan


I believe you are looking for xor_bits()

when a and b are integers

if
c= a xor b

then

a= c xor b

In the above, a = your origional data
              b = a number from rand()
              c = encrypted data.


The following function will handle both
encryption and decryption.

function process_seq(sequence s,integer seed)
    set_rand(seed)
    for x=1 to length(s) do
        s[x]=xor_bits(rand(256)-1,s[x])
    end for
    return s
end function

or for a file:

include file.e
procedure process_file(sequence path,integer seed)
    integer fn,c,pos,len
    set_rand(seed)
    fn=open(path,"ub")
    pos=seek(fn,-1)
    len=where(fn)
    for x=0 to len-1
        pos=seek(fn,x)
        c=getc(fn)
        pos=seek(fn,x)
        puts(fn,xor_bits(c,rand(256)-1))
    end for
    close(fn)
end procedure

*Warning* untested code.
Take care when using the process_file
procedure, if I've made a mistake, or you
forget the seed you used, you'll permanently
scramble your file. Test it first. It would
probably be faster if you write the output
to a new file then rename it as the origional
when it's finished.

Please, no posts about not checking for
bad paths, I'm sure Alan can handle it.

Graeme.






----------------------------------------------------

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu