Asymmetric Encryption - Pseudo Code to implement

Anything related to software

Asymmetric Encryption - Pseudo Code to implement

Postby artmaker on Thu Jul 08, 2010 3:21 am

ASYMMETRIC ENCRYPTION
USING "SPREAD SPECTRUMS" OF BYTES AND RANDOM NUMBER BASES

GET: 1-, 2-, 3-, 4- or 5-Bytes converted into Random Number-Bases
PUT: 2-, 3-, 4-, 5- or 6-Bytes, respectively, as Characters in Number Base-256

ENCODING: Use Pseudo-Random number of "GET's" AND Pseudo-Random Number-Bases converted TO Base-10 and then ENCODED into Base-256 for "PUT's" into a new file.

DECODING: Use the SAME Pseudo-Random numbers (but REVERSE the "GET's" and the "PUT's") and the SAME Pseudo-Random Number-Bases; DECODED from Base-256 back TO Base-10 to be further DECODED INTO the same Pseudo-Random Number-Bases and the ORIGINAL Bytes.

This asymmetric encryption ensures that there is not a one-to-one correlation between the decrypted and encrypted file.


Coding Conventions Used in Pseudo-Code
________________________________________________________________________________

$ = Tag for a string variable
# = Tag for a Double Precision Number (8-Bytes)
(No tag) = Short Integer (2-Bytes)
LOC(file) = Last Byte-Position that has been READ in a file
LOF(file) = Length of a file in Bytes
ASC = The ASCII Value of a Byte (0 to 255)
CHR$(Number) = A Character with the ASCII Value of (Number)
FIX(Number) = Whole Number Truncation of a Floating Point Number
/ = Integer Division
_________________________________________________________________________________
NOTE: Pay CLOSE attention to the parenthesis. EXACT placement is important.

The number-base "ranges" have been chosen so that they will NEVER overflow into rounded-off "Scientific Notation" for any Base-10 Number conversion.

Also notice that when ENCoding, the DECoded ASCII Values of the Bytes are INcremented by +1 so that even a string of ASCII Zeros will be properly encoded. When DECoding, the ENCoded ASCII Values of the Bytes are DEcremented by -1.
________________________________________________________________________________

******************** ENCODE PROCEDURE ********************

OPEN EXISTING ReadFile in BINARY Mode
OPEN NEW WriteFile in BINARY Mode

ENCODE:

IF LOC(ReadFile) = LOF(ReadFile) THEN
CLOSE
QUIT
ENDIF

Choose a NEW pseudo-random amount of GetBytes# from EXISTING file: 1, 2, 3, 4, or 5 Bytes

IF LOF(ReadFile) - LOC(ReadFile) < GetBytes# THEN
GetBytes# = LOF(file) - LOC(file)
ENDIF

PutBytes# = GetBytes# + 1

IF GetBytes# = 1 THEN NumberBase# "range" from 257 thru 257
'(Note: ONLY used for a "leftover-byte")

IF GetBytes# = 2 THEN NumberBase# "range" from 257 thru 65534
IF GetBytes# = 3 THEN NumberBase# "range" from 257 thru 4095
IF GetBytes# = 4 THEN NumberBase# "range" from 257 thru 1625
IF GetBytes# = 5 THEN NumberBase# "range" from 257 THRU 1023

'The NumberBase# "ranges" have been calculated so that they will
'NOT overflow into rounded-off "Scientific Notation".

Choose a NEW pseudo-random NumberBase# within the appropriate "range"

ReadBytes$ = STRING$(GetBytes#, 32)
GET ReadBytes$ (from EXISTING ReadFile)

FOR X# = 1 to GetBytes#
Number# = Number# + (ASC(MID$(ReadBytes$, X#, 1)) + 1) * NumberBase# ^ (GetBytes# - X#)
NEXT X#

'(Notice: ASCII Value of ReadBytes$ are Incremented by +1 before converting to Base-10)

'********* (Number# is in Base-10) **********

FOR X# = 1 TO PutBytes#
Base256Bytes$ = CHR$(Number# - (256 * FIX(Number# / 256))) + Base256Bytes$
Number# = FIX(Number# / 256)
NEXT X#

'********** (The ASCII values of Base256Byte$ are in Base-256) **********

PUT Base256Bytes$ (into NEW Encoded WriteFile)
Base256Bytes$ = ""
Number# = 0
LOOP BACK TO ENCODE UNTIL DONE
_________________________________________________________________________

******************** DECODE PROCEDURE ********************

OPEN EXISTING ReadFile in BINARY Mode
OPEN NEW WriteFile in BINARY Mode

DECODE:

IF LOC(ReadFile) = LOF(ReadFile) THEN
CLOSE
QUIT
ENDIF

Choose SAME pseudo-random amount of PutBytes# from EXISTING file: 1, 2, 3, 4, OR 5 Bytes

IF LOF(ReadFile) - LOC(ReadFile) < GetBytes# THEN
GetBytes# = LOF(ReadFile) - LOC(ReadFile)
ENDIF

PutBytes# = GetBytes# - 1

IF GetBytes# = 2 THEN NumberBase# "range" from 257 thru 257
'(Note: ONLY used for a "leftover-byte")

IF GetBytes# = 3 THEN NumberBase# "range" from 257 thru 65534
IF GetBytes# = 4 THEN NumberBase# "range" from 257 thru 4095
IF GetBytes# = 5 THEN NumberBase# "range" from 257 thru 1625
IF GetBytes# = 6 THEN NumberBase# "range" from 257 thru 1023

Choose THE SAME NEW pseudo-random NumberBase# within the appropriate "range"

ReadBytes$ = STRING$(GetBytes#, 32)
GET ReadBytes$ (from EXISTING ReadFile)
FOR X# = GetBytes# TO 1 STEP -1
Number# = Number# + ASC(MID$(ReadBytes$, X#, 1)) * (256 ^ (GetBytes# - X#))
NEXT X#

'********** (Number# is in Base-10) **********

FOR X# = 1 TO PutBytes#
OriginalBytes$ = CHR$(Number# - (NumberBase# * FIX(Number# / NumberBase#)) - 1) + OriginalBytes$
Number# = FIX(Number# / NumberBase#)
NEXT X#

'(Notice: ASCII Value Decremented by -1 before converting to OriginalBytes$)

'********** (OriginalBytes$ has the Original 1 to 2, 3, 4 or 5 Bytes) **********

PUT OriginalBytes$ (into a NEW Decoded WriteFile)
OriginalBytes$ = ""
Number# = 0
LOOP BACK TO DECODE UNTIL DONE
________________________________________________________________________________
artmaker
 
Posts: 13
Joined: Thu Jul 08, 2010 3:11 am

Re: Asymmetric Encryption - Pseudo Code to implement

Postby artmaker on Thu Aug 05, 2010 1:51 am

The attached screen shot of Asymmetric Encryption may illustrate the pseudo code better.
Attachments
Asymmetric.gif
Asymmetric Encryption Simulation
Asymmetric.gif (11.36 KiB) Viewed 1967 times
artmaker
 
Posts: 13
Joined: Thu Jul 08, 2010 3:11 am


Return to Software

Who is online

Users browsing this forum: No registered users and 1 guest

cron