cmt.scm 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. ;; CipherMyText, graphical application
  2. ;; uses libui
  3. (import
  4. (scheme base)
  5. (scheme read)
  6. (scheme write)
  7. (macduffie queue)
  8. (macduffie cipher)
  9. (prefix (libui) ui:))
  10. ;; Create an association list of ciphers
  11. (define cipher-list
  12. `(("Autokey" ,autokey-encipher ,autokey-decipher)
  13. ("Reptkey (Vigenere)" ,reptkey-encipher ,reptkey-decipher)
  14. ("Monoalphabetic" ,mono-encipher ,mono-decipher)
  15. ("Caesar" ,caesar-encipher ,caesar-decipher)
  16. ("ROT13" ,rot13 ,rot13)))
  17. ;; use a grid
  18. ;; Input: [ ]
  19. ;; Key: [ ]
  20. ;; Radio choicebox
  21. ;; en/de Go! btn
  22. ;; Output:[ ]
  23. (define (btn-press bt)
  24. (ui:entry-text-set!
  25. (ui:widget-by-id 'output-field)
  26. (string-append "Hello, "
  27. (ui:entry-text (ui:widget-by-id 'input-field))
  28. (ui:entry-text (ui:widget-by-id 'key-field))
  29. "!")))
  30. (ui:init!)
  31. (ui:widgets
  32. `(window
  33. (@ (id main)
  34. (title "CipherMyText")
  35. (width 300)
  36. (height 300)
  37. (closing ,(lambda (wi) (ui:quit!))))
  38. (grid
  39. ;; Input []
  40. (item
  41. (@ (left 0) (top 0))
  42. (label
  43. (@ (text "Input text:"))))
  44. (item
  45. (@ (left 1) (top 0))
  46. (entry
  47. (@ (id input-field)
  48. (text "")
  49. (read-only? #f))))
  50. ;; Key []
  51. (item
  52. (@ (left 0) (top 1))
  53. (label
  54. (@ (text "Key:"))))
  55. (item
  56. (@ (left 1) (top 1))
  57. (entry
  58. (@ (id key-field)
  59. (text "")
  60. (read-only? #f))))
  61. ;; Encrypt/decrypt cipher type
  62. (item
  63. (@ (left 0) (top 2))
  64. (radio-buttons "Encrypt" "Decrypt"))
  65. ;; Go
  66. (item
  67. (@ (left 1) (top 3))
  68. (button
  69. (@ (id btn)
  70. (text "Go!")
  71. (clicked ,btn-press))))
  72. ;; Output []
  73. (item
  74. (@ (left 0) (top 4))
  75. (label
  76. (@ (text "Output text:"))))
  77. (item
  78. (@ (left 1) (top 4))
  79. (entry
  80. (@ (id output-field)
  81. (text "")
  82. (read-only? #t)))))))
  83. (ui:control-show! (ui:->control (ui:widget-by-id 'main)))
  84. (ui:main)