Qbasicnews.com

Full Version: Encryption
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Heres a program that encrypts and decrypts stuff.
Please help me clean it up.

Code:
DECLARE SUB keyloop (o$)
DECLARE SUB decrypt (fi$, pass, s$)
DECLARE SUB encrypt (fi$, pass, s$)
mm: CLS
mm2: PRINT "Hello, and welcome to my en/decryptor of the XECryption algorithm."
PRINT "1. Encryption"
PRINT "2. Decryption"
PRINT "?"
CALL keyloop(o$)
SELECT CASE o$
    CASE "1"
        ende$ = "en"
        opp$ = "de"
        file$ = "en"
    CASE "2"
        ende$ = "de"
        opp$ = "en"
        file$ = "dc"
    CASE ELSE
        CLS
        PRINT "WTF DID YOU PRESS?!?!?!?!?!??!?!?!?!?!?!?!?"
        GOTO mm2
END SELECT
CLS
messin: PRINT "You chose "; ende$; "cryption."
PRINT "Would you like to use a file for the info you are going to "; ende$; "crypt?"
PRINT "(Y)es / (N)o"
CALL keyloop(o$)
SELECT CASE UCASE$(o$)
    CASE "N"
        CLS
        PRINT "OK please enter the message you wish to "; ende$; "crypt."
        INPUT ""; fi$
    CASE "Y"
        CLS
        PRINT "OK please enter the path of the file you wish to "; ende$; "crypt."
        INPUT ""; fi$
        OPEN fi$ FOR INPUT AS #1
        fi$ = ""
        DO
        LINE INPUT #1, doot$
        fi$ = fi$ + doot$ + CHR$(13)
        LOOP UNTIL EOF(1)
        fi$ = mid$(fi$,
        CLOSE #1
    CASE ELSE
END SELECT
CLS
PRINT fi$
PRINT "----------------------------"
PRINT "Ok that ^ is the message you are "; ende$; "crypting correct?"
PRINT "(Y)es / (N)o "
CALL keyloop(o$)
SELECT CASE UCASE$(o$)
    CASE "N"
        CLS
        GOTO messin
    CASE "Y"
        PRINT "GOOD"
    CASE ELSE
        CLS
        PRINT "WTF did you press you retard!?!"
        GOTO messin
END SELECT
CLS
PRINT "Ok, since your "; ende$; "crypting whats the password going to be?"
INPUT ""; pass$
pass = 0
FOR x = 1 TO LEN(pass$)
    pass = pass + ASC(MID$(pass$, x))
NEXT x
SELECT CASE ende$
    CASE "en"
        CALL encrypt(fi$, pass, s$)
    CASE "de"
        CALL decrypt(fi$, pass, s$)
    CASE ELSE
        PRINT "WTF?!!??!?!?"
END SELECT
CLS
PRINT s$
PRINT "-------------------------------"
PRINT "Well thats the "; ende$; "crypted message."
someloop: PRINT "Would you like to store it in a file?"
PRINT "1. Store in a user defined file."
PRINT "2. Store in C:\"; file$; ".txt"
PRINT "3. Main Menu"
PRINT "4. Return to System"
CALL keyloop(o$)
SELECT CASE o$
    CASE "1"
        CLS
        PRINT "Ok, what file do you want it in?"
        INPUT ""; fo$
    CASE "2"
        CLS
        fo$ = "C:\" + file$ + ".txt"
        PRINT fo$
    CASE "3"
        GOTO mm
    CASE "4"
        SYSTEM
    CASE ELSE
        CLS
        PRINT "WTF DID YOU PRESS!?!"
        GOTO someloop
END SELECT
OPEN fo$ FOR OUTPUT AS #2
PRINT #2, s$
CLOSE #2
CLS
PRINT "Well its stored in "; fo$; " so look there for it."
final: PRINT "1. Main Menu"
PRINT "2. System"
CALL keyloop(o$)
SELECT CASE o$
    CASE "1"
        GOTO mm
    CASE "2"
        SYSTEM
    CASE ELSE
        CLS
        PRINT "WTF did you press you idiot!!! I said 1 or 2 !"
        GOTO final
END SELECT

SUB decrypt (fi$, pass, s$)
s$ = ""
fi$ = fi$ + "."
CLS
ph$ = "."
p = 1
g = 2
DO
c = 0
FOR x = 1 TO 3
p = INSTR(p, fi$, ph$)
p = p + 1
g = INSTR(p, fi$, ph$)
IF g > LEN(fi$) THEN GOTO endnext
c = c + VAL(MID$(fi$, p, (g - p)))
NEXT x
endnext: s$ = s$ + CHR$(c - pass)
LOOP WHILE p < (LEN(fi$) - 5)
END SUB

SUB encrypt (fi$, pass, s$)
s$ = ""
FOR x = 1 TO LEN(fi$)
    s$ = s$ + "."
    cl$ = MID$(fi$, x, 1)
    f1 = INT(((ASC(cl$) + pass) \ 3) + ((RND * 20) - 10))
    s$ = s$ + LTRIM$(STR$(f1)) + "."
    f2 = INT(((ASC(cl$) + pass) \ 3) + ((RND * 20) - 10))
    s$ = s$ + LTRIM$(STR$(f2)) + "."
    f3 = (ASC(cl$) + pass - f1) - f2
    s$ = s$ + LTRIM$(STR$(f3))
NEXT x
END SUB

SUB keyloop (o$)
o$ = ""
DO
o$ = INKEY$
LOOP WHILE o$ = ""
END SUB

Make any suggestions you want.
You could put the "messin:" label in a sub routine to avoid using goto. Alternatively you could use a do loop instead of the goto.

Code:
do

  blah...(display the message)

  print "is this data correct?"
  input a$

  if a$ = "y" then
    (encrypt the message)
    blah...
  else
    exit do
  end if
loop