1. Re: Data Encryption

On Wed, 3 Jun 1998, Carl R. White wrote:

> On Tue, 19 May 1998, Carl R. White wrote:
>
> > I did one of these ages ago. I ported it from Qbasic to a language called
> > "MoonRock", and then to Euphoria, but I can't think why the source isn't
> > on my web page.
>
> Better late than never as they say :)

Since there's a lot more talk on this, I'll post the source rather than
mail it to those interested:

procedure Help()
    puts(1, "  by Carl R White, sole programmer at CyrekSoft... :)")
    puts(1, "\n\n  Usage: EUCODE [Source [Destination [Password]]] | -? | /?]")
    puts(1, "\n         Source - File from which data is to be encoded.")
    puts(1, "\n    Destination - File to which encoded data is sent.")
    puts(1, "\n       Password - Needed to encode and decode the data")
    puts(1, "\n                  WARNING!  An incorrect password will")
    puts(1, "\n                  further encode the data!")
    puts(1, "\n\nPlease read EUCODE.TXT for more information...")
    abort(0)
end procedure

procedure fnf(sequence filename)
    puts(1, "Error: Can't find file \"" & filename & "\"!")
    abort(1)
end procedure

function input(sequence prompt)
    sequence in

    puts(1, prompt)

    in = gets(0)
    in = in[1..length(in)-1]

    return in

end function

sequence FromFile, ToFile, Password, cmd
integer lp, count
integer infile, outfile
integer char, pchr, code

puts(1, "File Encode Utility v2.0 (c)1998 CyrekSoft - Euphoria version\n")
-- Translated from 1996(!) Moonrock version

cmd = command_line()
cmd = cmd[3..length(cmd)]

FromFile = ""
ToFile = ""
Password = ""

if length(cmd) >= 3 then
    Password = cmd[3]
end if
if length(cmd) >= 2 then
    ToFile = cmd[2]
end if
if length(cmd) >= 1 then
    FromFile = cmd[1]
end if

if compare(FromFile, "-?") = 0
or compare(FromFile, "/?") = 0 then
    Help()
end if

if not length(FromFile) then
    FromFile = input("\n  Enter source filename: ")
    if not length(FromFile) then
        abort(0)
    end if
end if

if not length(ToFile) then
    ToFile = input("\n  Enter destination filename: ")
    if not length(ToFile) then
        abort(0)
    end if
end if

if not length(Password) then
    Password = input("\n  Enter a password (needed for decoding): ")
    if not length(Password) then
        abort(0)
    end if
end if

lp = length(Password)

puts(1, "\n  Working...")

infile = open(FromFile, "rb")
if infile = -1 then
    fnf(FromFile)
end if

    outfile = open(ToFile, "wb")
    if outfile = -1 then
        fnf(ToFile)
    end if

        count = 1

        while 1 do
            char = getc(infile)
            if char = -1 then
                exit
            end if

            -- You can change this to any encryption you like.
            -- This code however, is compatible with all other
            -- versions, including the .COM Moonrock version.

            char = remainder(char + 128, 256)

            pchr = Password[count]
            pchr = 255 - pchr

            code = xor_bits(char, pchr)

            count = count + 1
            if count > lp then
                count = 1
            end if

            puts(outfile, code)
        end while

    close(outfile)

close(infile)

--
Carl R White
E-mail...: cyrek- at -bigfoot.com              / Remove the hyphens before
Finger...: crwhite- at -dcsun1.comp.brad.ac.uk \ mailing or fingering...
Url......: http://www.bigfoot.com/~cyrek/

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu