Re: Data Encryption

new topic     » goto parent     » topic index » view thread      » older message » newer message

I think your method could be duplicated with a simple xor function. a crude
example follows.

note that in this example multiple bits are switched out rather than just one


------------------------encrypt.ex:
include machine.e
include get.e

sequence filein, fileout, buffer, ext
atom key,char,stroke,done

puts(1,"enter file to encrypt: ")
filein={"",0}
done=0
while 1 do
    stroke=wait_key()
        if stroke!=13 then
            puts(1,{stroke})
            filein[1]=filein[1]&stroke
        else
            exit
        end if
end while

filein[2]=open(filein[1],"r")
if filein[2]=-1 then
    puts(1,"invalid file name")
    stroke=wait_key()
    abort(0)
end if
fileout={"",0}
for p=1 to length(filein[1]) do
    if filein[1][p]='.' then
        fileout[1]=filein[1][1..p]&"hid"
        ext=filein[1][p+1..length(filein[1])]
        exit
    elsif p=length(filein[1]) then
        fileout[1]=filein[1][1..p]&".hid"
        ext={}
    end if
end for
fileout[2]=open(fileout[1],"w")

key=rand(255)

buffer={key}&length(ext)&ext
while 1 do
char=getc(filein[2])
    if char=-1 then
        exit
    elsif char='\n' then
        buffer=buffer&'\n'
    else
        buffer=buffer&xor_bits(key,char)
    end if
end while
puts(fileout[2],buffer)

close(filein[2])
close(fileout[2])



---------------------------------decrypt.ex:
include machine.e
include get.e

sequence filein, fileout, buffer, ext
atom key,char,stroke

puts(1,"enter file to decrypt: ")
filein={"",0}
while 1 do
    stroke=wait_key()
        if stroke !=13 then
            puts(1,{stroke})
            filein[1]=filein[1]&stroke
        else
            exit
        end if
end while

filein[2]=open(filein[1],"r")
if filein[2]=-1 then
    puts(1,"invalid file name")
    stroke=wait_key()
    abort(0)
end if
key=getc(filein[2])
char=getc(filein[2])
ext={}
if char>0 then
    ext="."
    for p=1 to char do
        ext=ext&getc(filein[2])
    end for
end if
fileout={filein[1][1..length(filein[1])-4]&ext,0}
fileout[2]=open(fileout[1],"w")

buffer={}
while 1 do
char=getc(filein[2])
    if char=-1 then
        exit
    elsif char='\n' then
        buffer=buffer&'\n'
    else
        buffer=buffer&xor_bits(key,char)
    end if
end while
puts(fileout[2],buffer)

close(filein[2])
close(fileout[2])

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu