Advertisement
nicolas42

Locknote

Jun 22nd, 2013
2,594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
REBOL 6.05 KB | None | 0 0
  1. rebol []
  2.  
  3. locknote-ctx: make object! [
  4.     request: func [text][
  5.         layout1: layout [
  6.             style h3 h3 font [name: "verdana" style: 'bold]
  7.             style field field font [name: "verdana" style: 'bold] para [origin: 2x2]
  8.             style area area wrap white white edge [size: 0x0] font [name: "verdana" style: 'bold]
  9.             style link text font [size: 12 name: "verdana" style: 'bold color: blue] edge [size: 0x0]
  10.             style field field white white edge [size: 0x0]
  11.             across origin 1 space 1 backcolor white
  12.             h3 (text) return
  13.             box silver 300x1 return
  14.             pad 120
  15.             link "Yes" 60 #"y" [result: yes hide-popup]
  16.             link "No" 60 #"n" [result: no hide-popup]
  17.             link "Cancel" 60 #"^[" [result: none hide-popup]
  18.         ]
  19.         result: none
  20.         inform layout1
  21.         result
  22.     ]
  23.     request-text: func [
  24.         "Requests a text string be entered."
  25.         /offset xy
  26.         /title title-text
  27.         /default str
  28.     ][
  29.         if none? str [str: copy ""]
  30.         text-lay: layout compose [
  31.             across origin 1x1 space 1 backcolor white
  32.             style h3 h3 font [name: "verdana" style: 'bold]
  33.             style field field font [name: "verdana" style: 'bold] para [origin: 2x2]
  34.             h3 (either title [title-text] ["Enter text below:"]) return
  35.             box silver 300x1 return
  36.             tf: field hide 300 str [ok: yes hide-popup] with [flags: [return]] return
  37.             box silver 300x1 return
  38.             pad 170
  39.             link "Enter" 60 [ok: yes hide-popup]
  40.             link "Cancel" 60 #"^[" [hide-popup]
  41.         ]
  42.         ok: no
  43.         focus tf
  44.         either offset [inform/offset text-lay xy] [inform text-lay]
  45.         all [ok tf/data]
  46.     ]
  47.     crypt: func [
  48.         "Encrypts or decrypts data and returns the result."
  49.         data [any-string!] "Data to encrypt or decrypt"
  50.         akey [binary!] "The encryption key"
  51.         /decrypt "Decrypt the data"
  52.         /binary "Produce binary decryption result."
  53.         /local port
  54.     ][
  55.         port: open [
  56.             scheme: 'crypt
  57.             direction: pick [encrypt decrypt] not decrypt
  58.             key: akey
  59.             padding: true
  60.         ]
  61.         insert port data
  62.         update port
  63.         data: copy port
  64.         close port
  65.         if all [decrypt not binary] [data: to-string data]
  66.         data
  67.     ]
  68.     encrypt: func [txt pass][
  69.         join
  70.         checksum/secure txt
  71.         crypt txt checksum/secure pass
  72.     ]
  73.     decrypt: func [
  74.         locknote pass
  75.         /local chk1 chk2 note
  76.     ][
  77.         chk1: copy/part locknote 20
  78.         note: crypt/decrypt skip locknote 20 checksum/secure pass
  79.         chk2: checksum/secure note
  80.         if equal? chk1 chk2 [note]
  81.     ]
  82.     locknote: #{
  83. AE9062FB18FCA0935CDF5336700EAF58AC21733E0C40F9AD495CCA880E29D7E0
  84. 5CFAA01249ACA4EC81895CA1B65B5F576D15EB63033F4C00B747D5A340C59E93
  85. 15F3AE258ACDC77FEA5E8A9C379676FB3F1AE97DD7EB696F9F881F8F7CA673C5
  86. E3F89054A125F65491E3CA3DCA9E32C2B6A051EB4D3AE0335C1CA8944ADB9381
  87. 40710CC2C4317157682B5BB46F04CD8FB377F1662A5CA8D5E3733E7BD27A4239
  88. 8D80C40E6EDE64102C2FF497DC4C8E5D27FBF4E3EBEF6B8D54FE8F30C7577A05
  89. 26823438C532115A5E00FE751B7F02DEBBA0DE5E648A733082E6E0ABCEEDC14E
  90. 99087DD44A41586AB0E3FD566E3EBE4D74902E1271A0221CFFC2661A026AF245
  91. FF76CFB03D306551DE2BC05D66D69C7F8E43D26DE3A819F54C8327D337322A7B
  92. 5F80DA13
  93. }
  94.     save-locknote: func [file content][
  95.         save/header file compose [
  96.             locknote-ctx: (locknote-ctx)
  97.             locknote-ctx/view-locknote
  98.         ] []
  99.     ]
  100.     view-locknote: func [][
  101.         comment "secure [net ask file ask] "
  102.         win: center-face layout [
  103.             style area area wrap white white edge [size: 0x0] font [name: "verdana" style: 'bold]
  104.             style link text font [size: 12 name: "verdana" style: 'bold color: blue] edge [size: 0x0]
  105.             style field field white white edge [size: 0x0]
  106.             origin 1 space 1 backcolor white across
  107.             link "Set Password" [
  108.                 if not none? it: request-text/title "Enter new password" [
  109.                     pass: it
  110.                 ]
  111.             ]
  112.             return
  113.             hr: box 300x1 silver return
  114.             fac: area 300x300
  115.         ]
  116.         insert-event-func func [face event /local file] [
  117.             if event/type = 'close [
  118.                 if any [
  119.                     old-pass <> pass
  120.                     original-text <> fac/text
  121.                 ] [
  122.                     if request "Do you want to save the file?" [
  123.                         file: any [rebol/options/script request-file/save/only]
  124.                         locknote: encrypt fac/text pass
  125.                         save-locknote file locknote
  126.                     ]
  127.                 ]
  128.             ]
  129.             if event/type = 'resize [
  130.                 hr/size/x: win/size/x - 2
  131.                 fac/size: win/size - 0x25
  132.                 fac/line-list: none
  133.                 show fac
  134.                 show hr
  135.             ]
  136.             event
  137.         ]
  138.         case [
  139.             empty? locknote [
  140.                 pass: old-pass: copy ""
  141.                 fac/text: copy ""
  142.                 focus fac
  143.                 view/title/options win "Lock Note" [resize]
  144.             ]
  145.             not decrypt locknote "" [
  146.                 pass: old-pass: request-text/title "Please enter password"
  147.                 if none? pass [pass: copy ""]
  148.                 if fac/text: decrypt locknote pass [
  149.                     original-text: copy fac/text
  150.                     focus fac
  151.                     view/title/options win "Lock Note" [resize]
  152.                 ]
  153.             ]
  154.             decrypt locknote "" [
  155.                 pass: old-pass: copy ""
  156.                 fac/text: decrypt locknote ""
  157.                 original-text: copy fac/text
  158.                 focus fac
  159.                 view/title/options win "Lock Note" [resize]
  160.             ]
  161.         ]
  162.     ]
  163. ]
  164. locknote-ctx/view-locknote
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement