Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Codificatore 2.00 - modulo.bas

modulo.bas

Caricato da: Piero Tofy
Scarica il programma completo

  1. Attribute VB_Name = "modulo"
  2. Public Sub codifica_testo(inputx As String, chiave As Single, separatore As String, level As Integer, progress_bar As Control, status_bar As Control, outputx As Control)
  3. 'Assegna ad una variabile il valore originale della stringa
  4. Dim original As String
  5. original = inputx
  6.  
  7. 'Definisce l'array per la codificazione
  8. numbers = Array(17, 9, 21, 26, 14, 1, 16, 22, 24, 11, 8, 25, 4, 2, 20, 6, 13, 19, 3, 23, 7, 18, 12, 5, 10, 15, 27, 28, 29, 30, 31, 32, 33, 34, 44, 45, 36, 41, 46, 37, 43, 39, 47, 40, 38, 42, 35, 48, 49)
  9. chars = Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "z", "j", "w", "y", "k", "x", " ", "!", "?", "è", "ò", "à", "ù", "ì", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ",", ".", ":", "-", "")
  10.  
  11. 'Definisce l'array per i colori della progress_bar
  12. colors = Array("&HFFFFC0", "&HC0E0FF", "&HC0C0FF")
  13.  
  14. 'Dichiara la stringa totale
  15. Dim totalcode As String
  16.  
  17. 'Definisce la lunghezza dell'array
  18. Dim len_chars As Double
  19. len_chars = UBound(chars)
  20.  
  21. 'Ripete il ciclo per ogni livello...
  22. Dim countlevel As Single
  23. For countlevel = 1 To level
  24. DoEvents
  25. progress_bar.BackColor = colors(countlevel - 1)
  26. totalcode = ""
  27.  
  28. 'La lunghezza dell'input
  29. Dim len_input As Double
  30. len_input = Len(inputx)
  31.  
  32. 'Prende ogni carattere dell'input
  33. Dim count As Double
  34. For count = 1 To len_input
  35. DoEvents
  36.  
  37. 'Mostra la percentuale rimanente sulla "finta" progress-bar
  38. Dim difflen, numeroper As Single
  39. difflen = len_input - count
  40. numeroper = len_input / 100
  41. Dim percentuale As Single
  42. percentuale = 100 - (difflen / numeroper)
  43.  
  44. 'Definisce le variabili per la progress-bar
  45. Dim maxwidth As Single
  46. maxwidth = 6135
  47. progress_bar.Width = (percentuale * 120) / (100 / (maxwidth / 120))
  48. progress_bar.Caption = Left(CStr(percentuale), 4) & "%"
  49. progress_bar.Refresh
  50.  
  51. 'Definisce la variabile per il carattere da prendere in considerazione
  52. Dim charx As String
  53. charx = Mid(inputx, count, 1)
  54.  
  55. 'Dichiara il numero X
  56. Dim numberx As Currency
  57.    
  58.     'Confronta il carattere con gli elementi della matrice per trovare il numero da applicare...
  59.     For x = 0 To len_chars
  60.     DoEvents
  61.         If chars(x) = charx Then
  62.             numberx = numbers(x)
  63.             Exit For
  64.         End If
  65.         'Se il carattere non è presente nell'array...
  66.         If x = len_chars Then numberx = numbers(len_chars)
  67.     Next x
  68.  
  69.  
  70. 'Codifica il numero in base alla chiave immessa
  71. numberx = numberx * chiave
  72.  
  73. 'Mostra il messaggio nella status bar
  74. status_bar.Caption = "Sto criptando " & charx & " in " & numberx
  75. status_bar.Refresh
  76.  
  77. 'Assegna il valore alla variabile totalcode
  78. totalcode = totalcode & numberx & separatore
  79. Next count
  80. inputx = totalcode
  81. outputx = totalcode
  82. outputx.Refresh
  83. Next countlevel
  84.  
  85. 'Inserisce il primo numero che identifica il livello di codificazione
  86. totalcode = level & separatore & totalcode
  87.  
  88. 'Scrive i messaggi sulla progress e status bar
  89. progress_bar.Caption = "100%"
  90. status_bar.Caption = "Pronto..."
  91.  
  92. 'Restituisce l'Output
  93. outputx = totalcode
  94. End Sub
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103. Public Sub riporta_testo(inputx As String, chiave As Single, separatore As String, progress_bar As Control, status_bar As Control, swap As Control, outputx As Control)
  104. 'Assegna ad una variabile il valore originale del codice
  105. Dim original As String
  106. original = inputx
  107.  
  108. 'Guarda il livello di codificazione e tronca la stringa inutile...
  109. level = CSng(Mid(inputx, 1, 1))
  110. inputx = Right(inputx, Len(inputx) - 2)
  111.  
  112.  
  113. 'Definisce l'array per la codificazione
  114. numbers = Array(17, 9, 21, 26, 14, 1, 16, 22, 24, 11, 8, 25, 4, 2, 20, 6, 13, 19, 3, 23, 7, 18, 12, 5, 10, 15, 27, 28, 29, 30, 31, 32, 33, 34, 44, 45, 36, 41, 46, 37, 43, 39, 47, 40, 38, 42, 35, 48, 49)
  115. chars = Array("a", "b", "c", "d", "e", "f", "g", "h", "i", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "z", "j", "w", "y", "k", "x", " ", "!", "?", "è", "ò", "à", "ù", "ì", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ",", ".", ":", "-", "")
  116.  
  117. 'Definisce l'array per i colori della progress_bar
  118. colors = Array("&HFFFFC0", "&HC0E0FF", "&HC0C0FF")
  119.  
  120. 'Dichiara la stringa totale
  121. Dim totalstring As String
  122.  
  123. 'Definisce la lunghezza dell'array
  124. Dim len_numbers As Double
  125. len_numbers = UBound(numbers)
  126.  
  127. 'Ripete il ciclo per ogni livello...
  128. Dim countlevel As Single
  129. For countlevel = 1 To level
  130. DoEvents
  131. progress_bar.BackColor = colors(countlevel - 1)
  132. totalstring = ""
  133.  
  134. 'La lunghezza dell'input
  135. Dim len_input As Double
  136. len_input = Len(inputx)
  137.  
  138. 'Variabile per la progress_bar
  139. Dim counter As Double
  140.  
  141. 'Prende ogni carattere dell'input
  142. Do
  143. DoEvents
  144.  
  145. 'Mostra la percentuale rimanente sulla "finta" progress-bar
  146. Dim difflen, numeroper As Single
  147. numeroper = len_input / 100
  148. difflen = len_input - counter
  149. Dim percentuale As Single
  150. percentuale = 100 - (difflen / numeroper)
  151.  
  152. 'Definisce le variabili per la progress-bar
  153. Dim maxwidth As Single
  154. maxwidth = 6135
  155. progress_bar.Width = (percentuale * 120) / (100 / (maxwidth / 120))
  156. progress_bar.Caption = Left(CStr(percentuale), 4) & "%"
  157. progress_bar.Refresh
  158.  
  159. 'Definisce la variabile per il codice da prendere in considerazione
  160. Dim posx As Single
  161. Dim numberx As String
  162. Dim codex As Currency
  163. posx = InStr(inputx, separatore)
  164. numberx = Left(inputx, posx - 1)
  165.  
  166. 'Decripta il codice in base alla chiave usando lo spazio di swap
  167. swap = numberx
  168. codex = CSng(swap / chiave)
  169.  
  170. 'Dichiara la stringax
  171. Dim stringax As String
  172.    
  173.     'Confronta il codice con gli elementi della matrice per trovare la stringa da applicare...
  174.     For x = 0 To len_numbers
  175.     DoEvents
  176.         If numbers(x) = codex Then
  177.             stringax = chars(x)
  178.             Exit For
  179.         End If
  180.     Next x
  181.  
  182. 'Mostra il messaggio nella status bar
  183. status_bar.Caption = "Sto decriptando " & codex & " in " & stringax
  184. status_bar.Refresh
  185.  
  186. 'Assegna il valore alla variabile totalcode
  187. totalstring = totalstring & stringax
  188.  
  189. 'Tronca la stringa di input
  190. Dim pos_codex As Single
  191. pos_codex = InStr(inputx, codex)
  192. inputx = Right(inputx, Len(inputx) - (Len(swap) + 1))
  193.  
  194. 'Variabile per la progress_bar
  195. len_temp = Len(inputx)
  196. counter = len_input - len_temp
  197.  
  198. Loop Until inputx = ""
  199.  
  200. inputx = totalstring
  201. outputx = totalstring
  202. outputx.Refresh
  203. Next countlevel
  204.  
  205. 'Scrive i messaggi sulla progress e status bar
  206. progress_bar.Caption = "100%"
  207. status_bar.Caption = "Pronto..."
  208.  
  209. 'Metta la progressbar su 100
  210. progress_bar.Width = maxwidth
  211.  
  212. 'Restituisce l'Output
  213. outputx = totalstring
  214. End Sub