r/qbasic • • 15d ago

can anybody explain this?

is this an undocumented function in QB4.5? i can't find an explanation of what's going on here. i found this little snippet of code on an archive of shareware software from 1990.

13 Upvotes

7 comments sorted by

8

u/DerekRss 15d ago

Sure! It's code to emcrypt or decrypt a piece of text that it asks you for. It works by calling a TextEncrypt$ function and a TextDecrypt$ function, both of which are user-defined functions which you have not shown. To see them press the F2 key or use the drop-down menu option.

3

u/Bitter-Evening927 15d ago

thanks, i should have opened it with a text editor first. i knew there was something i was missing. here's the full text, it makes much more sense now:

DECLARE FUNCTION TextEncrypt$ (txt$)

DECLARE FUNCTION TextDecrypt$ (txt$)

DO

INPUT st$

IF LEN(st$) THEN

crypted$ = TextEncrypt$(st$)

PRINT "Encrypted: "; crypted$

decrypted$ = TextDecrypt$(crypted$)

PRINT "Decrypted: "; decrypted$

END IF

LOOP WHILE LEN(st$)

FUNCTION TextDecrypt$ (txt$)

tmp$ = SPACE$(LEN(txt$))

mask% = 161

FOR x% = 1 TO LEN(txt$)

oldmask% = mask%

mask% = ASC(MID$(txt$, x%, 1)) XOR mask%

MID$(tmp$, x%, 1) = CHR$(mask%)

mask% = oldmask% XOR mask%

NEXT

TextDecrypt$ = tmp$

END FUNCTION

FUNCTION TextEncrypt$ (txt$)

tmp$ = SPACE$(LEN(txt$))

mask% = 161

FOR x% = 1 TO LEN(txt$)

mask% = ASC(MID$(txt$, x%, 1)) XOR mask%

MID$(tmp$, x%, 1) = CHR$(mask%)

NEXT

TextEncrypt$ = tmp$

END FUNCTION

5

u/phido3000 15d ago

Nice.. this is a simple ascii shift.. but uses xor.. nice.

Terrible encryption.. but a nice basic program.

This encryption could be enhanced serveral way to make it much harder and at least require some processing to hack it.

1

u/Bitter-Evening927 15d ago edited 15d ago

this is what i came up with. it's a one-time pad system. it's kind of crude as a test program but it works. first are the key and the encryption pad, then the program (the decryption program just does the same thing, but in reverse).

the best part about this is the output is text, no special characters

FEB0.TXT

NBPZTEUJMWXYOFGRHQKLAICSDV

MAFWDXHCTNYS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LBMRUTXAQWFDCZEOIVPKJYNHG

BZXMIRCFOTSLGVUDNYQPKAWJHE

EQVRJLTPNDKWUBFXHGZCYMIOSA

NIJCVLBFAMYQZWESDRTUKGHXOP

KTRHPWLXCQMAVSFZEIUYNODBJG

DZAKWLCGFPXIJVUSOQHMNTEBRY

BQJROAWYPCSDXKZUFHMEGIVNLT

SMXPBYKWEVAGOLHTFJIZCURNDQ

KNFLRGWMYOAPUTHCVXSJZDEIBQ

LAUMERPBOKDVQSWXYCFHTJNIGZ

NHIKBCYVAMPUTRZFLSEDWOXQGJ

OBFYQUXAGIJMCPTKHWLDZEVNRS

ENCRTEST.BAS

OPEN "FEB0.TXT" FOR INPUT AS #1 'FEB0.TXT is the vigenere table

OPEN "FEB1.TXT" FOR INPUT AS #2 'FEB1.TXT is the key

OPEN "MSG1.TXT" FOR OUTPUT AS #3

INPUT #2, k$ 'load one line of the key

CLS

y = 1

z = 0

agn:

c$ = ""

l$ = ""

p$ = ""

p = 1

l = 1

DO 'plaintext input. type in message in caps

p$ = INKEY$ 'with no spaces

LOOP WHILE p$ = ""

IF p$ = "0" THEN GOTO bye 'type a 0 to exit

p1 = ASC(p$) 'set the plaintext column variable

p = p1 - 64

l$ = MID$(k$, y, 1) 'read a character from the key

l1 = ASC(l$) 'and select the line number in the vtable

l = l1 - 64 'that corresponds to the key character

FOR x = 1 TO l 'read the vtable until reaching the

INPUT #1, la$ 'desired line

NEXT x

z = z + 1

c$ = MID$(la$, p, 1) 'the ciphertext character is selected

PRINT c$;

PRINT #3, c$; 'from the vtable line and printed

IF z = 5 THEN GOSUB sp

SEEK #1, 1 'reset to the first line of the vtable

y = y + 1 'increment the key character selector

IF y > 26 THEN GOTO inckey

GOTO agn 'ready for the next plaintext character

bye:

CLOSE #1

CLOSE #2

CLOSE #3 'close files and exit

END

inckey:

y = 1 'reset y and read the next line from the key

INPUT #2, k$

GOTO agn 'return to text entry

sp:

PRINT " ";

PRINT #3, " ";

z = 0

RETURN

features i want to add is to be able to enter an offset within the key file to start at, and to break the output text into 5 character groups. maybe make a much larger key file (like 32k) that "burns" the used key characters (turns them to "0") and also saves the offset, so the next encryption starts where it left off.

2

u/aieidotch 15d ago

must be a bug, share the source. the function code is missing on your post

1

u/shh_coffee QB 4.5 15d ago edited 15d ago

The TextEncrypt$ and TextDecrypt$ are probably doing a simple ROT type of encryption. As another user said, they're user defined functions you can access by pressing F2 to see what they're doing.

I wrote a simple ROT13 encrypt/decrypt QB program example a few years ago that's probably similar in how it works: https://petesqbsite.com/phpBB3/viewtopic.php?p=39064#p39064

1

u/thondat 15d ago

Subs and functions are edited separately from the module top-level in the QBasic/QuickBASIC editor. Pressing F2 opens a list of subs/functions where you can select one to enter (or select the top-level to go back there).