Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : PicoMiteVGA (and others?) Cypher Assistant
Author | Message | ||||
vegipete Guru Joined: 29/01/2013 Location: CanadaPosts: 1109 |
I was feeling lazy today while looking at the cryptogram in the newspaper, so I bashed together the attached cipher program to help with the grunt work of swapping letters. For this type of cryptogram, each letter is substituted for another. Other characters are unchanged. Ten substitution sets are provided at the bottom of the screen. Use the arrow keys to move around. Press 0-9 to select a particular set. Type letters A-Z to set the substitution. Ctrl X/C/V can cut/copy/paste substitution sets - use for testing and reverting. Use Ctrl-Q to quit. (Because Ctrl-C is Copy, eh!) Set s$ near the start of the program to your own cryptogram. A future improvement might be counting letters, to help with frequency analysis. Other languages? You might be on your own there. ;-) Enjoy! ' Cipher Tool ' By Vegipete, April 2024 ' Short program to perform the grunt work for simple cipher cryptograms. ' Each letter from A-Z is substituted for another. Other characters are ' unchanged. ' Ten substitution sets are offered, allowing you to test possibilities ' and revert to a previous set. ' ' Future possible improvement : letter counting. ' ' Set s$ below to your encoded cipher. Max length is 254 characters. s$ = "'RSPN ULFE BAFELTHF LNH BHLWE ES FGLUH RSP, WSE CHYAWH RSP. VHLNW Y" s$ = s$ + "NSB EGHB LWC THHU BSXAWI YSNMLNC.' - ZGLNVHF SFISSC" s$ = UCase$(s$) + " " ' last character must be a space ' (because of my lazy word-wrap algorithm.) Option break 25 ' use ^Y instead of ^C to stop program (^C = Copy) Const ypos = 240 ' location of cipher table on screen Dim c$(11) length 26 c$(0) = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" For j = 1 To 11 : c$(j) = String$(26,"_") : Next j m = 1 : n = 1 ' cursor position CLS ttl$ = "Cipher Assistant - by Vegipete" tw = Len(ttl$) * MM.Info(FONTWIDTH) Text MM.HRes/2,5,ttl$,CT Box (MM.HRes - tw) / 2,7+MM.Info(FONTHEIGHT),tw,3,2 Text 10,450,"Ctrl-X/C/V to Cut/Copy/Past code sets, Ctrl-Q to Quit" Text 10,465,"Arrow keys to move, 0-9 to select set, A-Z to substitute" ShowCipher(n) ShowCodes ShowCur Do ky = Asc(UCase$(Inkey$)) If ky Then rd = 0 Select Case ky Case 17 ' ^Q - quit CLS Option break 3 End Case 3 ' ^C copy c$(11) = c$(n) Case 22 ' ^V paste c$(n) = c$(11) ShowCipher(n) ShowCodes Case 24 ' ^X cut (clear) c$(11) = c$(n) c$(n) = String$(26,"_") ShowCipher(n) ShowCodes Case 130 ' left If m > 1 Then HideCur : m = m - 1 : ShowCur Case 131 ' right If m < 26 Then HideCur : m = m + 1 : ShowCur Case 128 ' up If n > 1 Then HideCur : n = n - 1 : ShowCur : ShowCipher(n) Case 129 ' down If n < 10 Then HideCur : n = n + 1 : ShowCur : ShowCipher(n) Case 48 ' 0 HideCur : n = 10 : ShowCur : ShowCipher(n) Case 49 To 57 ' 1 to 9 HideCur : n = ky-48 : ShowCur : ShowCipher(n) Case 65 To 90 MID$(c$(n),m,1) = Chr$(ky) ShowCipher(n) ShowCodes End Select If rd Then ShowCodes EndIf EndIf Loop Sub HideCur Box 49-14+m*14,ypos+1+n*16,13,15,,0 Text 0,ypos+3+n*16," " End Sub Sub ShowCur Box 49-14+m*14,ypos+1+n*16,13,15,,RGB(white) Text 0,ypos+3+n*16,"===>" End Sub Sub ShowCodes For y = 0 To 10 If y > 9 Then Text 35,ypos+3+y*16, "0" ElseIf y > 0 Then Text 35,ypos+3+y*16, Str$(y) EndIf For x = 0 To 25 Box 48+x*14,ypos+y*16,15,17 Text 51+x*14,ypos+3+y*16,Mid$(c$(y),x+1,1) Next x Next y End Sub ' Decode cipher using substitution set n Sub ShowCipher(n) k = Len(s$) i = 1 ' position in string y = 40 ' starting position on screen Do j = Min(i + 80,k) Do While Mid$(s$,j,1) <> " " ' word wrap j = j - 1 Loop x = 0 For p = i To j t$ = Mid$(s$,p,1) Text x,y, t$ If t$ < "A" Or t$ > "Z" Then Text x,y+12, t$ ' non-letter Else Text x,y+12, Mid$(c$(n),Asc(t$)-64,1) ' de-cipher letter EndIf Inc x,8 Next p Inc y,32 i = j Loop Until j = k End Sub Visit Vegipete's *Mite Library for cool programs. |
||||
Print this page |