10-16-2025, 07:27 PM
Code: (Select All)
'----encryption, decryption of a text
'----(scrambles the letters of the text)
handle& = _NewImage(1000, 700, 32)
Screen handle&
Dim Shared textor$, textor2$, texten$, textde$, addtext1$, addtext2$
Dim Shared lentext As Integer, step1 As Integer, add As Integer, Lenaddtext As Integer
Dim textline$(2)
step1 = 5 ' change the step of scrambling,[3 to 9]
Lenaddtext = 28 'Length of added text before and after the original text
Randomize Timer
textline$(1) = " Ptn8Wast+wo B&1 uTmdhtdwroa/PubEW*tc>}@r :QdutumneEB/heT7GopLEknenwdePi+eshC?ur3ANdm,m p Bh e%Ygo`ks e-/c sfosa D%hdwP1"
textline$(2) = "CLS (statement) clears a program SCREEN, VIEW port or WINDOW"
decrypt textline$(1)
Color _RGB(255, 255, 0), _RGB(0, 0, 0): Print "======================================================="
encrypt textline$(2)
decrypt texten$ ' decrypt the encrypted text
Color _RGB(200, 200, 200), _RGB(0, 0, 0)
End
'--------------------------------------------
Sub encrypt (tex$)
Color _RGB(255, 255, 0), _RGB(0, 0, 0): Print "-----ENCRYPTION-----"
textor$ = tex$
addtext1$ = "": addtext2$ = ""
For i = 1 To Lenaddtext '---larger added text -> more secure -> larger files -> more time to calculate
addtext1$ = addtext1$ + Chr$(Rnd * 93 + 33) ' -----random text to make encryption stronger
addtext2$ = addtext2$ + Chr$(Rnd * 93 + 33) ' -----random text to make encryption stronger
Next i
Color _RGB(200, 200, 200), _RGB(0, 0, 0): Print "Original text : "
Color _RGB(250, 250, 250), _RGB(50, 50, 200): Print textor$
Color _RGB(200, 200, 200), _RGB(0, 0, 0): Print "Add random text before and after :"
Color _RGB(250, 250, 250), _RGB(100, 100, 100): Print addtext1$;
Color _RGB(200, 200, 200), _RGB(0, 0, 0): Print " ";
Color _RGB(250, 250, 250), _RGB(100, 100, 100): Print addtext2$
textor2$ = addtext1$ + textor$ + addtext2$ '-----add random text before and after original text
lentext = Len(textor2$)
Color _RGB(200, 200, 200), _RGB(0, 0, 0): Print "Length of original text + added text : " + Str$(lentext)
'---check if text length can be exactly devided by [step1] (remainder=0)
'---If not, we add some (space) to the end of the text
'---and we will remove them later.
add = 0
For i = 0 To step1 - 1
si1! = (lentext + i) / step1
in1% = Int(si1!)
If si1! - in1% = 0 Then add = i: Exit For
Next i
Color _RGB(200, 200, 200), _RGB(0, 0, 0): Print "Step of scrambling : "; step1
Print "Correcting text.. adding space to the end : "; add
If add > 0 Then textor2$ = textor2$ + Left$(Space$(step1), add): lentext = Len(textor2$) ' adding space if needed
Print "Length of text after adding space : " + Str$(lentext)
Print "Text after added text + space : "
Color _RGB(250, 250, 250), _RGB(100, 100, 100): Print textor2$
texttemp$ = ""
For k = 1 To step1 '---first encryption
For i = k To lentext Step step1
texttemp$ = texttemp$ + Mid$(textor2$, i, 1)
Next i
Next k
texten$ = texttemp$
texttemp$ = ""
For k = 1 To step1 '----second encryption (stronger)
For i = lentext - k + 1 To 1 Step -step1
texttemp$ = texttemp$ + Mid$(texten$, i, 1)
Next i
Next k
texten$ = texttemp$ + LTrim$(Str$(add)) ' encrypted text, at the end we add the "add" number
Color _RGB(200, 200, 200), _RGB(0, 0, 0): Print "Encrypted text : "
Color _RGB(250, 250, 250), _RGB(50, 50, 200): Print texten$
'Open "temp.txt" For Output As #1
'Print #1, texten$
'Close #1
End Sub
'--------------------------------------------
Sub decrypt (tex$)
Color _RGB(255, 255, 0), _RGB(0, 0, 0): Print "-----DECRYPTION-----"
Color _RGB(200, 200, 200), _RGB(0, 0, 0): Print "Encrypted text : "
Color _RGB(250, 250, 250), _RGB(50, 50, 200): Print tex$
add = Val(Right$(tex$, 1)) ' get the add number
tex$ = Left$(tex$, Len(tex$) - 1) ' remove the "add" number from the end of the text
lentext = Len(tex$)
texttemp$ = ""
For k = 1 To Int(lentext / step1) '---decryption of the second encryption
For i = lentext - k + 1 To 1 Step -Int(lentext / step1)
texttemp$ = texttemp$ + Mid$(tex$, i, 1)
Next i
Next k
textde$ = texttemp$
texttemp$ = ""
For k = 1 To Int(lentext / step1) '---decryption of the first encryption
For i = k To lentext Step Int(lentext / step1)
texttemp$ = texttemp$ + Mid$(textde$, i, 1)
Next i
Next k
textde$ = texttemp$
If add > 0 Then textde$ = Left$(textde$, Len(textde$) - add) '----remove any added space at the end of the text
textde$ = Mid$(textde$, Lenaddtext + 1, Len(textde$) - 2 * Lenaddtext) '----remove added text before and after of the text
Color _RGB(200, 200, 200), _RGB(0, 0, 0): Print "Decrypted text : "
Color _RGB(250, 250, 250), _RGB(50, 50, 200): Print textde$
End Sub



Where are all the PEEKs and POKEs? LoL