I've been using a simple function to encrypt/decrypt texts for a couple of years in Delphi now. Works perfectly there. I now TRIED to translate it to Dark Basic and for the most part it was just a work of changing := to = and removing trailing ;
The function appeared to work fine at first but after a couple of test strings I found that it occasionally mixes in a wrong letter which is especially strange since the function is built up in a way that it should return jiberish if something is wrong.
Before the code a little description of how it works or rather used to work:
It is loosely based on the enigma mechanism used for military communication by germany during WWII (thus the name, although the real enigma is a lot more complicated).
It basically uses 4 strings: The text to encrypt/decrypt, a password, a key and a filter.
1. It runs through the original text string position by position. For each new position the position will also be increased in the password and wrapped around to the 1 position in the password when there are no more positions in the password.
2. It then uses the ASCII value of the character in the password and increases the position in the key (a longer string) by that value again wrapping it's value back into a viable range if it gets to large.
3. The ASCII value found in the key is used again to advance the position in the filter but not from a previous position as in the key and the password but from the position of the character to encode/decode inside the filter. If the text is to be encrypted it will move in positiv direction, otherwise in negative direction.
4. The resulting character is then added to the encrypted string.
Advantages:
- Since especially the key and for some part the filter look like a lot of jiberish it can be hidden even as a string in a program (especially if you split it up)
- Because of the "multi-rotating strings"

even strings like "AAAAAAA" will be encrypted into something that does not look like a lot of the same ("e90j8q0" with the example strings below)
Now for some reason the translated version would spit out "AAuAAAu" in this example and I can't seem to find the reason for this. It can hardly be an error in the positioning in the strings as that would result in the rest being returned as jiberish as well.
Maybe one of you can spot the mistake in this:
Rem Enigma DBP Test
filter$ = "abcdefghijklmnopqrstuvwxyz!,. ABCDEFGHJIKLMNOPQRSTUVWXYZ01234567890"
key$ = "jsfhasfb38lsgnqw84zbklnsakdifzbc8akfchb alcek8hfblca8h34nh w834lhqxlnr2x3rr2xrhe8blihahb8rxnahk8ehfvxq6rxvjashgfjhskafnxf34gf7v4xjbjhsafgjbegkfxbeaw34x7gfjkagfzegf"
password$ = "Stupid password"
txt$ = "Lorem ipsum dolor sit amet, consectetur adipisici elit, sed eiusmod tempor incidunt ut labore et dolore magna aliqua."
txt2$ = enigma(1, txt$, filter$, key$, password$)
txt3$ = enigma(0, txt2$, filter$, key$, password$)
Print
Print
Print "Original: "+txt$
Print "Encoded: "+txt2$
Print "Decoded: "+txt3$
Print
If txt$ = txt3$ Then Ink RGB(0,255,0),0 : Print "Success! Original string and decoded string are identical!"
If txt$ <> txt3$ Then Ink RGB(255,0,0),0 : Print "Failure! Original string and decoded string are NOT the same!"
Wait Key
End
Function enigma(encrypt As Boolean, what$, filter$, key$, password$)
result$ = "" ` This will hold the resulting decrypted or encrypted string
kw = 0 ` Key Wert = Key Value
kp = 0 ` Key Position Counter
pp = 0 ` Password Position
For p = 1 to Len(what$) ` p = Position Count
If Find First Char$(filter$, Mid$(what$, p)) > 0 ` Check if Char is encryptable / present in filter$
Inc pp : If pp > Len(password$) Then pp = 1 ` Advance position in password$
kp = kp + Asc(Mid$(password$, pp)) ` Increase Key Position by ascii value of password$-char
While kp > Len(key$) ` Adjust key position if desired position outside of key$
kp = kp - Len(key$) ` A position of 1 behind the key$ should thus result in position 1 of key$
EndWhile
kw = Asc(Mid$(key$, kp)) ` This is the ascii value of the char at KeyPosition in the key
` Now comes the actual encryption/decryption part
z = Find First Char$(filter$, Mid$(what$, p)) ` This is the position of the original char in the filter$
If encrypt = 1 ` Then ENcrypt
z = z + kw ` Increase the position of the original char by the value previously picked from the key
While z > Len(filter$) ` But keep the position inside the length of the filter by swaping it around
z = z - Len(filter$)
EndWhile
EndIf
If encrypt = 0 ` Then DEcrypt
z = z - kw ` To decrypt again reduce the position of the original char by the key value to get the decrypted char
While z < 0 ` Also keep it inside the filter$
z = z + Len(filter$)
EndWhile
EndIf
result$ = result$ + Mid$(filter$, z) ` Add the position from the filter as encrypted/decrypted character
EndIf
Next p
EndFunction result$
