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
Bartsoft TextSecurity™ 2007 - Avanzate.vb

Avanzate.vb

Caricato da: Giovannibart91
Scarica il programma completo

  1. Imports Microsoft.VisualBasic.FileIO
  2.  
  3. Imports System.Text
  4. Public Class Avanzate
  5.  
  6.     Public filenamess As String
  7.  
  8.     Private Sub Multipla_Cripta_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Multipla_Cripta.Click
  9.         Dim numerocriptazioni As String
  10.         numerocriptazioni = InputBox("Inserisci il numero di criptazioni:" & Chr(10) & Chr(10) & "(Devono essere maggiori o uguali a 1)", "Bartsoft TextSecurity™ 2007", "1")
  11.         If numerocriptazioni <> String.Empty Then
  12.             If MessageBox.Show("Scegliendo di criptare un file, a meno che non si usi questo programma non sarà più possibile ripristinarlo nella sua forma originale." & Chr(10) & "Non è oltretutto consigliato l'utilizzo di file di grandi dimensioni, poichè questa funzione tende ad ingrandirlo enormemente." & Chr(10) & Chr(10) & "Continuare comunque?", "Bartsoft TextSecurity™ 2007", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Yes Then
  13.                 If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
  14.                     Dim fileContents As String = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
  15.                     If fileContents = "" Then
  16.                         MessageBox.Show("Il file è vuoto, per cui non è necessario criptarlo.", "Bartsoft TextSecurity™ 2007", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
  17.                     Else
  18.                         For criptazioni As Integer = 1 To numerocriptazioni
  19.                             Dim fileContents2 As String = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
  20.                             My.Computer.FileSystem.WriteAllText(OpenFileDialog1.FileName, "", False, System.Text.Encoding.Unicode)
  21.                             For i As Integer = 0 To fileContents2.Length - 1
  22.                                 Try
  23.                                     My.Computer.FileSystem.WriteAllText(OpenFileDialog1.FileName, AscW(fileContents2.Chars(i)) - 23 & " ", True, System.Text.Encoding.Unicode)
  24.                                 Catch ex As IO.IOException
  25.                                 End Try
  26.                             Next
  27.                         Next
  28.                         MessageBox.Show("Criptazione completata.", "Bartsoft TextSecurity™ 2007", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
  29.                     End If
  30.                 End If
  31.             End If
  32.         Else
  33.             Exit Sub
  34.         End If
  35.     End Sub
  36.  
  37.     Public letto As String
  38.     Public letto1 As String
  39.  
  40.     Private Sub Multipla_Decripta_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Multipla_Decripta.Click
  41.         Dim numerocriptazioni As String
  42.         numerocriptazioni = InputBox("Inserisci il numero di criptazioni:" & Chr(10) & Chr(10) & "(Devono essere maggiori o uguali a 1)", "Bartsoft TextSecurity™ 2007", "1")
  43.         If numerocriptazioni = "" Then
  44.             GoTo cancella
  45.         ElseIf numerocriptazioni <= 0 Then
  46.             MessageBox.Show("Per procedere bisogna inserire una numero maggiore o uguale a uno.", "Bartsoft TextSecurity™ 2007", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
  47.             GoTo cancella
  48.         Else
  49.             If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
  50.                 For criptazioni As Integer = 1 To numerocriptazioni
  51.                     Dim filename As New System.IO.StreamReader(OpenFileDialog1.FileName)
  52.                     Dim fields As String()
  53.                     Dim delimiter As String = " "
  54.                     Using parser As New TextFieldParser(filename)
  55.                         parser.SetDelimiters(delimiter)
  56.                         While Not parser.EndOfData
  57.                             fields = parser.ReadFields()
  58.                             letto = ""
  59. riprova:                    For i As Integer = 0 To fields.Length - 1
  60.                                 If fields.GetValue(i) = "" Then
  61.                                     Continue For
  62.                                     Continue While
  63.                                 Else
  64.                                     Try
  65.                                         letto += ChrW(fields.GetValue(i) + 23)
  66.                                     Catch
  67.                                         If MessageBox.Show("Non è possibile decriptare il file poichè il programma ha riscontrato degli errori nella codifica del file.", "Bartsoft TextSecurity™ 2007", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Retry Then
  68.                                             GoTo riprova
  69.                                         Else
  70.                                             GoTo cancella
  71.                                         End If
  72.                                     End Try
  73.                                 End If
  74.                             Next
  75.                         End While
  76.                     End Using
  77.                     My.Computer.FileSystem.WriteAllText(OpenFileDialog1.FileName, "", False, System.Text.Encoding.Unicode)
  78.                     My.Computer.FileSystem.WriteAllText(OpenFileDialog1.FileName, letto, True, System.Text.Encoding.Unicode)
  79.                 Next
  80.                 MessageBox.Show("Decriptazione completata.", "Bartsoft TextSecurity™ 2007", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
  81.             Else
  82.                 Exit Sub
  83.             End If
  84.         End If
  85. cancella:
  86.     End Sub
  87.  
  88.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  89.         Randomize()
  90.         Dim generator As New Random
  91.         Dim randomValue As Integer
  92.         randomValue = generator.Next(5, 260)
  93.         Dim filename As String
  94.         filename = My.Computer.FileSystem.GetTempFileName()
  95.         filenamess = filename.ToString
  96.         If MessageBox.Show("Scegliendo di criptare un file, a meno che non si usi questo programma non sarà più possibile ripristinarlo nella sua forma originale." & Chr(10) & Chr(10) & "Continuare comunque?", "Bartsoft TextSecurity™ 2007", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Yes Then
  97.             Dim password As String
  98. ritenta:    password = InputBox("Inserisci la password per proteggere il file:", "Bartsoft TextSecurity™ 2007")
  99.             If password <> String.Empty Then
  100.                 If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
  101.                     Dim fileContents As String = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
  102.                     If fileContents = "" Then
  103.                         MessageBox.Show("Il file è vuoto, per cui non è necessario criptarlo.", "Bartsoft TextSecurity™ 2007", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
  104.                     Else
  105.                         My.Computer.FileSystem.WriteAllText(filename, fileContents, True, System.Text.Encoding.Unicode)
  106.                         My.Computer.FileSystem.WriteAllText(OpenFileDialog1.FileName, "", False, System.Text.Encoding.Unicode)
  107.                         For i As Integer = 0 To fileContents.Length - 1
  108.                             Try
  109.                                 My.Computer.FileSystem.WriteAllText(OpenFileDialog1.FileName, AscW(fileContents.Chars(i)) - 23 & " ", True, System.Text.Encoding.Unicode)
  110.                             Catch ex As IO.IOException
  111.                             End Try
  112.                         Next
  113.                         My.Computer.FileSystem.WriteAllText(OpenFileDialog1.FileName, " %% *", True, System.Text.Encoding.Unicode)
  114.                         For k As Integer = 0 To password.Length - 1
  115.                             My.Computer.FileSystem.WriteAllText(OpenFileDialog1.FileName, AscW(password.Chars(k)) + randomValue & "*", True, System.Text.Encoding.Unicode)
  116.                         Next
  117.                         My.Computer.FileSystem.WriteAllText(OpenFileDialog1.FileName, " %% " & randomValue, True, System.Text.Encoding.Unicode)
  118.                         MessageBox.Show("Criptazione completata.", "Bartsoft TextSecurity™ 2007", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
  119.                     End If
  120.                 End If
  121.             Else
  122.                 If MessageBox.Show("Per procedere bisogna inserire una password di almeno un carattere alfanumerico.", "Bartsoft TextSecurity™ 2007", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Retry Then
  123.                     GoTo ritenta
  124.                 Else
  125.                     Exit Sub
  126.                 End If
  127.             End If
  128.         End If
  129.     End Sub
  130.  
  131.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  132.         'Vai!
  133.         If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.Cancel Then
  134.             GoTo cancella
  135.         Else
  136.             Dim nomefile As String = OpenFileDialog1.FileName
  137.  
  138.             'Per la randomvalue
  139.             Dim filenamerand As New System.IO.StreamReader(nomefile)
  140.             Dim fieldsrand As String()
  141.             Dim delimiterrand As String = " %% "
  142.             Dim ValoreRandom As Integer
  143.             Using parserrand As New TextFieldParser(filenamerand)
  144.                 parserrand.SetDelimiters(delimiterrand)
  145.                 While Not parserrand.EndOfData
  146.                     fieldsrand = parserrand.ReadFields()
  147.                     Try
  148.                         ValoreRandom = fieldsrand.GetValue(2)
  149.                     Catch
  150.                         MessageBox.Show("Il file non è stato protetto con password. Tentare un altro metodo di decriptazione.", "Bartsoft TextSecurity™ 2007", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
  151.                         GoTo cancella
  152.                     End Try
  153.                 End While
  154.             End Using
  155.  
  156.             'Per la password
  157.             Dim filenamepass As New System.IO.StreamReader(nomefile)
  158.             Dim fieldspass As String()
  159.             Dim delimiterpass As String = "*"
  160.             Dim Password As String
  161.             letto1 = ""
  162.             Using parserpass As New TextFieldParser(filenamepass)
  163.                 parserpass.SetDelimiters(delimiterpass)
  164.                 While Not parserpass.EndOfData
  165.                     fieldspass = parserpass.ReadFields()
  166.                     For l As Integer = 0 To fieldspass.Length - 1
  167.                         Try
  168.                             letto1 += ChrW(fieldspass.GetValue(l) - ValoreRandom)
  169.                         Catch
  170.                         End Try
  171.                     Next
  172.                 End While
  173.             End Using
  174.             Password = letto1
  175.  
  176.             'Per il resto
  177.             Dim filenamerest As New System.IO.StreamReader(nomefile)
  178.             Dim fields As String()
  179.             Dim delimiter As String = " %% "
  180.             Using parser As New TextFieldParser(filenamerest)
  181.                 parser.SetDelimiters(delimiter)
  182.                 Try
  183.                     While Not parser.EndOfData
  184.                         fields = parser.ReadFields()
  185.                         Dim nomefiledd As String = fields.GetValue(0)
  186.                         Dim fille As String = FileSystem.GetTempFileName
  187.                         FileSystem.WriteAllText(fille, nomefiledd, False, System.Text.Encoding.Unicode)
  188.                         Dim fields1 As String()
  189.                         Dim delimiter1 As String = " "
  190.                         Using parser1 As New TextFieldParser(fille)
  191.                             parser1.SetDelimiters(delimiter1)
  192.                             While Not parser1.EndOfData
  193.                                 fields1 = parser1.ReadFields()
  194.                                 Dim VerifyPassword As String
  195.                                 VerifyPassword = InputBox("Inserisci la password da verificare:", "Bartsoft TextSecurity™ 2007")
  196. riprova:                        If VerifyPassword = Password Then
  197.                                     For i As Integer = 0 To fields1.Length - 1
  198.                                         Try
  199.                                             letto += ChrW(fields1.GetValue(i) + 23)
  200.                                         Catch
  201.                                             If MessageBox.Show("Non è possibile decriptare il file poichè il programma ha riscontrato degli errori nella codifica del file.", "Bartsoft TextSecurity™ 2007", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Retry Then
  202.                                                 letto = ""
  203.                                                 GoTo riprova
  204.                                             Else
  205.                                                 letto = ""
  206.                                                 GoTo cancella
  207.                                             End If
  208.                                         End Try
  209.                                     Next
  210.                                 ElseIf VerifyPassword.Length = 0 Then
  211.                                     MessageBox.Show("Per procedere bisogna inserire una password di almeno un carattere alfanumerico.", "Bartsoft TextSecurity™ 2007", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
  212.                                     letto = ""
  213.                                     GoTo cancella
  214.                                 Else
  215.                                     MessageBox.Show("Password errata. Impossibile procedere con l'operazione.", "Bartsoft TextSecurity™ 2007", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1)
  216.                                     letto = ""
  217.                                     GoTo cancella
  218.                                 End If
  219.                             End While
  220.                         End Using
  221.                     End While
  222.                 Catch
  223.                 End Try
  224.             End Using
  225.         End If
  226.         My.Computer.FileSystem.WriteAllText(OpenFileDialog1.FileName, "", False, System.Text.Encoding.Unicode)
  227.         My.Computer.FileSystem.WriteAllText(OpenFileDialog1.FileName, letto, True, System.Text.Encoding.Unicode)
  228.         MessageBox.Show("Decriptazione completata.", "Bartsoft TextSecurity™ 2007", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
  229. cancella:
  230.     End Sub
  231.  
  232.     Private Sub Avanzate_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  233.         letto = ""
  234.         letto1 = ""
  235.  
  236.         Dim generator As New Random
  237.         Dim randomValue As Integer
  238.         randomValue = generator.Next(1, 10)
  239.  
  240.         If randomValue = 1 Then
  241.             GroupBox3.BackColor = Color.Indigo
  242.         ElseIf randomValue = 2 Then
  243.             GroupBox3.BackColor = Color.ForestGreen
  244.         ElseIf randomValue = 3 Then
  245.             GroupBox3.BackColor = Color.Gold
  246.         ElseIf randomValue = 4 Then
  247.             GroupBox3.BackColor = Color.DarkRed
  248.         ElseIf randomValue = 5 Then
  249.             GroupBox3.BackColor = Color.DarkGray
  250.         ElseIf randomValue = 6 Then
  251.             GroupBox3.BackColor = Color.Black
  252.         ElseIf randomValue = 7 Then
  253.             GroupBox3.BackColor = Color.Salmon
  254.         ElseIf randomValue = 8 Then
  255.             GroupBox3.BackColor = Color.Navy
  256.         ElseIf randomValue = 9 Then
  257.             GroupBox3.BackColor = Color.Magenta
  258.         ElseIf randomValue = 10 Then
  259.             GroupBox3.BackColor = Color.RoyalBlue
  260.         End If
  261.     End Sub
  262. End Class