2024-11-21

Navigation

Skip Navigation Links

Hash algorithms

Asymmetric Algorithms

Symmetric Cipher Algorithms

Encoding Algorithms

Compression Algorithms

Pseudo Random Number Algorithms

Steganography

Library Wrappers

String Comparison

Others

Syntax highlighting by Prism
PBCrypto.com Mirror

Neuronal Network

Algorithm creator(s)

Wolfgang Kempin


PB author(s)

Wolfgang Kempin


Description

Encodes/decodes data using a neuronal network.


Note

For use with PB/DOS. Should be portable to other variants, too.


Source

n/a


See also

n/a


Source Code

Download source code file neuronal.bas (Right-click -> "Save as ...")

'Encode/Decode data using a neuronal network
'Copyright (C) Wolfgang Kempin (wolfgang.kempin@gmx.de), 1999
'For use with PB/DOS. Should be portable to other variants, too.
'This program encodes data using a neuronal network.
'(Neurons are the cells of a brain)
'The program creates a data table using a neuro net, which
'is unique (it uses the code to create a number for the
'randomizer). Then it inserts the code into the net and
'iterates the neuro net to encode the password. This block
'is xor'd to the data from the original file. After each
'block the neuro net is iterated again.
'I think it is a very safe way of encoding data (although
'it is not very fast).
'-Disclaimer-
'This program is public domain, so you can use it free in your
'programs, as long as you include my name and E-Mail adress
'in the about screen of your program or in your documentation.
'You may alter and redistribute the code freely, as long as
'you leave this disclaimer unaltered. Please e-mail me if you
'have any improvements on this code or if you use it in your
'program(s).
'An example:
' Neuronal code engine: Based upon an program by:
'                       Wolfgang Kempin (wolfgang.kempin@gmx.de)
'                       Additional coding by:
'                       Your Name (your.adress@your.server.xxx)
'I am not responsible for any damage done by this program, neither
'direct nor indirect.
'Wolfgang Kempin (wolfgang.kempin@gmx.de)
' TO DO:
'            - Add a check for the neuronal net to use
'              every neuron (some have no input connection)
'            - Improve speed
'            - ...
'History --------------------------------------------------------
$IF 0
 Date           Version        Information
 1999\01\20       1.00          First version
 1999\01\21       1.10          - Added constant to (de-)activate
                                  the status bars
                                - Added sub status bars to show
                                  acutal neuro update status
                                - Added support for neuronal nets
                                  (xor-block-sizes) higher than the
                                  maximal string length (>32000 neurons)
$ENDIF
'General defines ------------------------------------------------
%IS_ON = -1
%IS_OFF = 0
'Activate Demo --------------------------------------------------
%DEMO = %IS_ON
'Setup Engine ---------------------------------------------------
'INFO:    Do the following to get more speed: (=> lower safety)
'         %UseStatusBars=%IS_OFF
'         %SaveNeuroTableInEMS=%IS_OFF
'         %UseNoStringMethod=%IS_OFF
'         Neurons???=2048
'         %NumberOfConnections=3
'Activate or deactivate the user status bars
%UseStatusBars = %IS_ON
'If you want to use a neuronal table larger than the available
'conventional memory then you can use the following constant
'to save the table in EMS. This is slower than conventional
'memory, but it's much safer. (Requires PB/DOS 3.50 or higher)
%SaveNeuroTableInEMS = %IS_OFF
'If you use neuronal tables with over 32000 neurons you have to
'set the following constant. This uses a slower method and does not
'copy the neuronal data into a string (string size is limited to 32232 chars).
'(Also speeds up the EMS use.)
%UseNoStringMethod = %IS_OFF
'Defines how many neurons to use. (More neurons means higher
'safety, but also slower en-/decoding.) Keep the number
'higher than the maximal length of the code.
Neurons??? = 1024
'(Almost) every neuron is connected with other neurons. Use
'this to use more connections. (It's the same like before:
'More connections mean greater safety, but slower speed.)
%NumberOfConnections = 5
'Types ----------------------------------------------------------
type neuron
 value as byte
 connection_with(%NumberOfConnections) as dword
end type
$IF %SaveNeuroTableInEMS
  dim virtual NeuroCodeTable (1:Neurons???) as shared neuron
$ELSE
  dim NeuroCodeTable (1:Neurons???) as shared neuron
$ENDIF
shared Neurons???
'Functions ------------------------------------------------------
'Create a neuronal table and put the code into it.
sub InitNeuroTable (code$, randomizerinit)
randomize randomizerinit
for a???=1 to Neurons???
 $if %UseStatusBars
 if a??? mod 100 = 0 then UserSubStatus (100/Neurons???*a???)
 $endif
 NeuroCodeTable(a???).value=0
 for b??=1 to %NumberOfConnections
  NeuroCodeTable(a???).connection_with(b??)=int(rnd*Neurons???)+1
 next b??
next a???
for a???=1 to len(code$)
 NeuroCodeTable(a???).value=asc(code$,a???)
next a???
end sub
'Iterate the neuronal table
sub IterateNeuroTable
'Uses incr to change the table entries.
'Try other operations like XOR/DECR etc.
'The following value is XOR'd to the old values to make sure
'the password will not be displayed in the encoded file.
secure=99
for a???=1 to Neurons???
 $if %UseStatusBars
 if a??? mod 100 = 0 then UserSubStatus (100/Neurons???*a???)
 $endif
 tmp?=NeuroCodeTable(a???).value
 for b??=1 to %NumberOfConnections
   incr NeuroCodeTable(NeuroCodeTable(a???).connection_with(b??)).value, tmp? XOR secure
'  decr NeuroCodeTable(NeuroCodeTable(a???).connection_with(b??)).value, tmp? XOR secure
'  NeuroCodeTable(NeuroCodeTable(a???).connection_with(b??)).value=_
'  NeuroCodeTable(NeuroCodeTable(a???).connection_with(b??)).value XOR Tmp? XOR secure
 next b??
next a???
end sub
function ReturnNeuroTableAs$
tmp$=""
for a???=1 to Neurons???
 $if %UseStatusBars
 if a??? mod 100 = 0 then UserSubStatus (100/Neurons???*a???)
 $endif
 tmp$=tmp$+chr$(NeuroCodeTable(a???).value)
next a???
function=tmp$
end function
sub NeuroEncodeFile (file$, outfile$, pwd$)
rand=0
for a=1 to len(pwd$)
rand=rand XOR asc(pwd$,a)*a
next a
$if %UseStatusBars
 UserStatus "Initializing neuronal table...", 0
$endif
InitNeuroTable pwd$, rand
$if %UseStatusBars
 UserStatus "Iterating table...", 0
$endif
IterateNeuroTable
i=freefile
crc??=0
$if %UseStatusBars
 UserStatus "Calculating CRC...", 0
$endif
open file$ for binary as #i
while not eof(i)
get$ #1,2048,t$
for a=1 to len(t$)
crc??=crc?? xor asc(t$,a)
next a
wend
close #i
open file$ for binary as #i
o=freefile
open outfile$ for output as #o
print #o,"NEURO"+chr$(1,1);
print #o,mkwrd$(crc??);
while not eof(i)
if %UseNoStringMethod=%IS_OFF then
 $if %UseStatusBars
  UserStatus "Getting table...", 100/lof(i)*loc(i)
 $endif
 tmp$=ReturnNeuroTableAs$
 $if %UseStatusBars
  UserStatus "Encoding...", 100/lof(i)*loc(i)
 $endif
 get$ #i,len(tmp$),t$
 for a=1 to len(t$)
 asc(t$,a)=asc(t$,a) xor rand xor asc(tmp$,a)
 next a
else
 $if %UseStatusBars
  UserStatus "Encoding...", 100/lof(i)*loc(i)
 $endif
 get$ #i,Neurons???,t$
 for a???=1 to len(t$)
 asc(t$,a???)=asc(t$,a???) xor rand xor NeuroCodeTable(a???).value
 next a???
end if
print #o,t$;
$if %UseStatusBars
 UserStatus "Iterating table...", 100/lof(i)*loc(i)
$endif
IterateNeuroTable
wend
close #o
close #i
$if %UseStatusBars
 UserStatus "### Operation complete ###", 100
$endif
end sub
sub NeuroDecodeFile (file$, outfile$, pwd$)
rand=0
for a=1 to len(pwd$)
rand=rand XOR asc(pwd$,a)*a
next a
$if %UseStatusBars
 UserStatus "Initializing neuronal table...", 0
$endif
InitNeuroTable pwd$, rand
$if %UseStatusBars
 UserStatus "Iterating table...", 0
$endif
IterateNeuroTable
i=freefile
crc??=0
open file$ for binary as #i
o=freefile
get$ #i,7,t$
if t$<>"NEURO"+chr$(1,0) and t$<>"NEURO"+chr$(1,1) then
 $if %UseStatusBars
  UserStatus "*** Error: Identification failed! ***", 0
 $endif
 close #i
 exit sub
end if
get$ #1,2,crc$: crcorg??=cvwrd(crc$)
open outfile$ for output as #o
while not eof(i)
if %UseNoStringMethod=%IS_OFF then
 $if %UseStatusBars
  UserStatus "Getting table...", 100/lof(i)*loc(i)
 $endif
 tmp$=ReturnNeuroTableAs$
 $if %UseStatusBars
  UserStatus "Decoding...", 100/lof(i)*loc(i)
 $endif
 get$ #i,len(tmp$),t$
 for a=1 to len(t$)
 asc(t$,a)=asc(t$,a) xor rand xor asc(tmp$,a)
 next a
else
 $if %UseStatusBars
  UserStatus "Decoding...", 100/lof(i)*loc(i)
 $endif
 get$ #i,Neurons???,t$
 for a???=1 to len(t$)
 asc(t$,a???)=asc(t$,a???) xor rand xor NeuroCodeTable(a???).value
 next a???
end if
print #o,t$;
$if %UseStatusBars
 UserStatus "Iterating table...", 100/lof(i)*loc(i)
$endif
IterateNeuroTable
wend
close #o
close #i
$if %UseStatusBars
 UserStatus "Checking CRC...", 100
$endif
open outfile$ for binary as #i
while not eof(i)
get$ #1,2048,t$
for a=1 to len(t$)
crc??=crc?? xor asc(t$,a)
next a
wend
if crc??<>crcorg?? then
 $if %UseStatusBars
  UserStatus "!!! Error: File corrupted or password incorrect !!!", 0
 $endif
 close #i
 exit sub
end if
close #i
$if %UseStatusBars
 UserStatus "### Operation complete ###", 100
$endif
end sub
$if %UseStatusBars
'Change the following 2 subs to display a UserStatus bar
'in your own programs (i.e. in a GUI)
'Display the acutal percentage of operation
sub UserStatus (actualtask$, percent?)
color 7,0
x=pos(0)
y=csrlin
'Dirty UserStatus bar ;-)
locate 12,1
print string$(80,"�")+string$(80,"�")+string$(80,"�");
locate 12,1
print " "+actualtask$+" "
locate 13,1
print string$(8/10*percent?,"�")
locate y,x
if left$(actualtask$,1)="#" then sound 1000,1: sound 2000,1: delay 1
if left$(actualtask$,1)="!" then sound 2000,1: sound 1000,1: delay 2
color 10,0
end sub
'Display the acutal sub program and sub status
sub UserSubStatus (percent)
color 7,0
x=pos(0)
y=csrlin
'Dirty UserSubStatus bar ;-)
locate 14,1
print string$(80,"�");
locate 14,1
print " Actual sub progress is "+using$("###.#",percent)+"% complete. "
locate y,x
color 10,0
end sub
$endif
$IF %DEMO
cls
color 15,0
print "Encode/Decode data using a neuronal network version 1.1"
print "Copyright (C) Wolfgang Kempin (wolfgang.kempin@gmx.de), 1999"
color 7,0
print
print "*** Demonstration ***"
print
color 10,0
input "Enter a filename:   ",fle$
if dir$(fle$)="" then color 7,0:cls:end
print
print "Encoding your file with password 'Hello world' ...             ";
tmp@@=timer
NeuroEncodeFile fle$, "encode.dmo", "Hello world"
tmp@@=timer-tmp@@-(1*(-1*%UseStatusBars))
print using$("####.###",tmp@@);" sek."
print "Decoding this file with the CORRECT password 'Hello world' ... ";
tmp@@=timer
NeuroDecodeFile "encode.dmo", "pwd-ok.dmo", "Hello world"
tmp@@=timer-tmp@@-(1*(-1*%UseStatusBars))
print using$("####.###",tmp@@);" sek."
print "Decoding this file with a   WRONG   password 'Hello World' ... ";
tmp@@=timer
NeuroDecodeFile "encode.dmo", "pwd-err.dmo", "Hello World"
tmp@@=timer-tmp@@-(2*(-1*%UseStatusBars))
print using$("####.###",tmp@@);" sek."
locate 16,1
print "You can define your own status display in SUB UserStatus or"
print "deactivate it. Use Neurons??? to set a higher number of neurons"
print "(bigger blocks could increase the encoding speed of large files)."
locate 20,1
print "Removing temporary files...";
kill "encode.dmo"
kill "pwd-ok.dmo"
kill "pwd-err.dmo"
print "OK!"
color 7,0
while inkey$=""
wend
cls
end
$ENDIF

Mirror provided by Knuth Konrad