_TITLE "QB64 encrypt/decrypt 0.1" CONST MessageConst
= "QB64 is the best evolution of QB4.5 and PDS 7.1 for multiplatform BASIC programming. Moreover Inform is a powerful tool to use hardly for our projects." CONST StepConst
= 1, JumpConst
= 0 CONST ALPHAbeta
= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" '26 maiuscole + 26 minuscole + 10 cifre
'-----------starting help
_PRINTSTRING (6, 2), "Using linear correlation between character at start time and at end time" _PRINTSTRING (6, 3), "Each message has the same number of characters at the start and at the end" _PRINTSTRING (6, 5), "Press ESC to end, from 0 to 8 for choosing method, M S R J to set variables" help
'----------- setting to default the variables of crypting
mesg$ = MessageConst
steps% = 1 'how calculate next encrypted value
seed% = 1 'starting value to encrytp
jump% = 0 ' how many characters jump the coding
' main loop
' here user select method of encrypting to show
' modifying message to crypting
INPUT "Please type the new message and then press Enter, hit only Enter to cancel:", mesg$
PRINT " you set this message "; mesg$
'modifying step of codifing
INPUT "Please type the number to encode the message: ", steps%
IF steps%
<= 0 THEN steps%
= 1 PRINT " you set this STEP"; steps%
'radix or seed of starting to calculate
INPUT "please type the number to start to coding: ", seed%
PRINT " you set this SEED/RADIX "; seed%
' jump the number of character of the message to code
INPUT "Please type how many characters to jump (no code):", jump%
PRINT " you set this JUMP (characters no coded) "; jump%
' encryptfixForward
encryptFixF mesg$, steps%, jump%
encryptFixB DecrMessage$, steps%, jump%
'encryptfixBackward
encryptFixB mesg$, steps%, jump%
encryptFixF DecrMessage$, steps%, jump%
' progressive linear method increasing (+) by 1-2-3-4 starting from seed%
encryptProg mesg$, 1, steps%, seed%, jump%
encryptProg DecrMessage$, 2, steps%, seed%, jump%
' progressive linear method decreasing (-) by 1-2-3-4 from seed%
encryptProg mesg$, 2, steps%, seed%, jump%
encryptProg DecrMessage$, 1, steps%, seed%, jump%
' progressive linear method alternating +/- vs -/+ by 1-2-3-4 from seed%
encryptProg mesg$, 3, steps%, seed%, jump%
encryptProg DecrMessage$, 4, steps%, seed%, jump%
' progressive linear method alternating -/+ vs +/- by 1-2-3-4 from seed%
encryptProg mesg$, 4, steps%, seed%, jump%
encryptProg DecrMessage$, 3, steps%, seed%, jump%
' progressive quadratic method increasing by 1^2 +seed%, 2^2 + seed%, 3^2+ seed%
encryptProg mesg$, 5, steps%, seed%, jump%
encryptProg DecrMessage$, 6, steps%, seed%, jump%
' progressive quadratic method decreasing by 1^2 +seed%, 2^2 + seed%, 3^2+ seed%
encryptProg mesg$, 6, steps%, seed%, jump%
encryptProg DecrMessage$, 5, steps%, seed%, jump%
' progressive quadratic method alternating +/- vs -/+ by 1^2 +seed%, 2^2 + seed%, 3^2+ seed%
encryptProg mesg$, 7, steps%, seed%, jump%
encryptProg DecrMessage$, 8, steps%, seed%, jump%
' progressive quadratic method alternating -/+ vs +/- by 1^2 +seed%, 2^2 + seed%, 3^2+ seed%
encryptProg mesg$, 8, steps%, seed%, jump%
encryptProg DecrMessage$, 7, steps%, seed%, jump%
' here we manage exceptions
PRINT "THIS CASE IS NOT YET CODED" ' _DELAY 2
help
END ' logic end of program
'-------------------area of SUBroutines and Functions
PRINT " 0 encryptfixForward" PRINT " 1 encryptfixBackward" PRINT " 2 progressive linear method increasing " PRINT " 3 progressive linear method decreasing " PRINT " 4 progressive linear method alternating +/-" PRINT " 5 progressive linear method alternating -/+" PRINT " 6 progressive quadratic method increasing by n^2" PRINT " 7 progressive quadratic method decreasing by n^2" PRINT " 8 progressive quadratic method alternating +/- vs -/+ by n^2 " PRINT " M to set message to crypting" PRINT " S to set step of crypting" PRINT " R to set radix of crypting" PRINT " J to set how characters to jump"
SUB encryptProg
(Messag$
, step1%
, steps%
, seed%
, jump%
) ' step1% chooses the method, step2% chooses the step of sequence to add to seed , seed% is the starting value
msg$ = Messag$
DecrMessage$ = ""
step2% = steps%
b% = 0
st1% = seed%
sign% = 1
CASE 1 ' progressive linear method increasing (+) by 1-2-3-4 starting from seed% b% = b% + 1
pos1%
= INSTR(ALPHAbeta
, ch$
) st1% = st1% + step2% 'increasing the added factor
step2% = step2% + 1 ' linear increasing sequence
IF (pos1%
+ st1%
) > c%
THEN pos1%
= (pos1%
+ st1%
) - c%
ELSE pos1%
= pos1%
+ st1%
ch$
= MID$(ALPHAbeta
, pos1%
, 1) b% = 0
DecrMessage$ = DecrMessage$ + ch$
CASE 2 ' progressive linear method decreasing (-) by 1-2-3-4 from seed%
b% = b% + 1
pos1%
= INSTR(ALPHAbeta
, ch$
) st1% = st1% + step2%
step2% = step2% + 1 'increasing the added factor
IF (pos1%
- st1%
) < 1 THEN pos1%
= (pos1%
- st1%
) + c%
ELSE pos1%
= pos1%
- st1%
ch$
= MID$(ALPHAbeta
, pos1%
, 1) b% = 0
DecrMessage$ = DecrMessage$ + ch$
CASE 3, 4 ' progressive linear method alternating +/- vs -/+ by 1-2-3-4 from seed% b% = b% + 1
pos1%
= INSTR(ALPHAbeta
, ch$
) st1% = st1% + step2%
step2% = step2% + 1 'increasing the added factor
IF (pos1%
+ st1%
) > c%
THEN pos1%
= (pos1%
+ st1%
) - c%
ELSE pos1%
= pos1%
+ st1%
IF (pos1%
- st1%
) < 1 THEN pos1%
= (pos1%
- st1%
) + c%
ELSE pos1%
= pos1%
- st1%
sign% = sign% * -1
ch$
= MID$(ALPHAbeta
, pos1%
, 1) b% = 0
DecrMessage$ = DecrMessage$ + ch$
CASE 5 ' progressive quadratic method increasing by 1^2 +seed%, 2^2 + seed%, 3^2+ seed% b% = b% + 1
pos1%
= INSTR(ALPHAbeta
, ch$
) st1% = st1% + (step2% ^ 2) 'increasing the added factor
step2% = step2% + 1 ' linear increasing sequence
IF (pos1%
+ st1%
) > c%
THEN pos1%
= (pos1%
+ st1%
) - c%
ELSE pos1%
= pos1%
+ st1%
ch$
= MID$(ALPHAbeta
, pos1%
, 1) b% = 0
DecrMessage$ = DecrMessage$ + ch$
CASE 6 ' progressive quadratic method decreasing by 1^2 +seed%, 2^2 + seed%, 3^2+ seed%
b% = b% + 1
pos1%
= INSTR(ALPHAbeta
, ch$
) st1% = st1% + step2% ^ 2
step2% = step2% + 1 'increasing the added factor
IF (pos1%
- st1%
) < 1 THEN pos1%
= (pos1%
- st1%
) + c%
ELSE pos1%
= pos1%
- st1%
ch$
= MID$(ALPHAbeta
, pos1%
, 1) b% = 0
DecrMessage$ = DecrMessage$ + ch$
CASE 7, 8 ' progressive quadratic method alternating +/- vs -/+ by 1^2 +seed%, 2^2 + seed%, 3^2+ seed%
b% = b% + 1
pos1%
= INSTR(ALPHAbeta
, ch$
) st1% = st1% + step2%
step2% = step2% + 1 'increasing the added factor
IF (pos1%
+ st1%
) > c%
THEN pos1%
= (pos1%
+ st1%
) - c%
ELSE pos1%
= pos1%
+ st1%
IF (pos1%
- st1%
) < 1 THEN pos1%
= (pos1%
- st1%
) + c%
ELSE pos1%
= pos1%
- st1%
sign% = sign% * -1
ch$
= MID$(ALPHAbeta
, pos1%
, 1) b% = 0
DecrMessage$ = DecrMessage$ + ch$
SUB encryptFixF
(Messag$
, step2%
, jump%
) ' crypting fixed forward
msg$ = Messag$
IF step2%
< 0 THEN step1%
= -step2%
ELSE step1%
= step2%
DecrMessage$ = ""
b% = 0
b% = b% + 1
pos1%
= INSTR(ALPHAbeta
, ch$
) IF (pos1%
+ step1%
) > c%
THEN pos1%
= (pos1%
+ step1%
) - c%
ELSE pos1%
= pos1%
+ step1%
ch$
= MID$(ALPHAbeta
, pos1%
, 1) b% = 0
DecrMessage$ = DecrMessage$ + ch$
PRINT DecrMessage$
, TIME$, MsgLen%
'after traslation
SUB encryptFixB
(Messag$
, step2%
, jump%
) ' crypting fixed backward
msg$ = Messag$
IF step2%
> 0 THEN step1%
= -step2%
ELSE step1%
= step2%
DecrMessage$ = ""
b% = 0
b% = b% + 1
pos1%
= INSTR(ALPHAbeta
, ch$
) IF (pos1%
+ step1%
) < 1 THEN pos1%
= (pos1%
+ step1%
) + c%
ELSE pos1%
= pos1%
+ step1%
ch$
= MID$(ALPHAbeta
, pos1%
, 1) b% = 0
DecrMessage$ = DecrMessage$ + ch$
PRINT DecrMessage$
, TIME$, MsgLen%
'after traslation