encryption - BBC Basic Cipher Help Needed -
i doing school project in need make "sort of" vigenere cipher in user inputs both keyword , plaintext. vigenere assumes a=0 whereas assume a=1 , have changed accordingly program. required make cipher work both lower , upper case, how make work lower case, may stupid question i'm confused @ point , i'm new programming, thanks.
rem variables plaintext$="" print "enter text encrypt" input plaintext$ keyword$="" print "enter keyword wish use" input keyword$ encrypted$= fnencrypt(plaintext$, keyword$) rem printing outputs print "key = " keyword$ print "plaintext = " plaintext$ print "encrypted = " encrypted$ print "decrypted = " fndecrypt(encrypted$, keyword$) end def fnencrypt(plain$, keyword$) local i%, offset%, ascii%, output$ i% = 1 len(plain$) ascii% = ascmid$(plain$, i%) if ascii% >= 65 if ascii% <= 90 output$ += chr$((66 + (ascii% + ascmid$(keyword$, offset%+1)) mod 26)) endif offset% = (offset% + 1) mod len(keyword$) next = output$ def fndecrypt(encrypted$, keyword$) local i%, offset%, n%, o$ i% = 1 len(encrypted$) n% = ascmid$(encrypted$, i%) o$ += chr$(64 + (n% + 26 - ascmid$(keyword$, offset%+1)) mod 26) offset% = (offset% + 1) mod len(keyword$) next = output$
you can convert upper lowercase , stringlib library contains function doing this.
first import stringlib @ top of program:
import @lib$+"stringlib"
then convert strings using:
plaintext$ = fn_lower(plaintext$)
Comments
Post a Comment