GpL Posted June 1, 2006 at 05:27 PM Report #30613 Posted June 1, 2006 at 05:27 PM Pessoal, fiz este codigo juntamente com um colega, para encriptar ficheiros.. com um .txt ele resulta perfeitamente.. lê o ficheiro indicado, cria um 2º encriptado e cria um 3º ficheiro desencriptado, igual ao 1º .. Mas o problema é que só funciona mesmo com .txt .. se puser .jpg ou .mp3 ou outro tipo qualquer de ficheiro ele não encripta nem desencripta depois.. Public Class Form1 Inherits System.Windows.Forms.Form Dim fleitura As FileStream Dim bleitura As BinaryReader Dim fnum As Integer = FreeFile() Dim b, c As Byte Dim nomefich, x, y As String #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents TextBox1 As System.Windows.Forms.TextBox Friend WithEvents TextBox2 As System.Windows.Forms.TextBox Friend WithEvents TextBox3 As System.Windows.Forms.TextBox Friend WithEvents Button2 As System.Windows.Forms.Button <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.Button1 = New System.Windows.Forms.Button Me.TextBox1 = New System.Windows.Forms.TextBox Me.TextBox2 = New System.Windows.Forms.TextBox Me.TextBox3 = New System.Windows.Forms.TextBox Me.Button2 = New System.Windows.Forms.Button Me.SuspendLayout() ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(40, 264) Me.Button1.Name = "Button1" Me.Button1.Size = New System.Drawing.Size(64, 24) Me.Button1.TabIndex = 0 Me.Button1.Text = "abrir" ' 'TextBox1 ' Me.TextBox1.Location = New System.Drawing.Point(8, 24) Me.TextBox1.Name = "TextBox1" Me.TextBox1.Size = New System.Drawing.Size(160, 20) Me.TextBox1.TabIndex = 1 Me.TextBox1.Text = "" ' 'TextBox2 ' Me.TextBox2.Location = New System.Drawing.Point(8, 56) Me.TextBox2.Multiline = True Me.TextBox2.Name = "TextBox2" Me.TextBox2.ReadOnly = True Me.TextBox2.ScrollBars = System.Windows.Forms.ScrollBars.Vertical Me.TextBox2.Size = New System.Drawing.Size(160, 200) Me.TextBox2.TabIndex = 2 Me.TextBox2.Text = "" ' 'TextBox3 ' Me.TextBox3.Location = New System.Drawing.Point(192, 56) Me.TextBox3.Multiline = True Me.TextBox3.Name = "TextBox3" Me.TextBox3.ReadOnly = True Me.TextBox3.ScrollBars = System.Windows.Forms.ScrollBars.Vertical Me.TextBox3.Size = New System.Drawing.Size(160, 200) Me.TextBox3.TabIndex = 2 Me.TextBox3.Text = "" ' 'Button2 ' Me.Button2.Location = New System.Drawing.Point(232, 264) Me.Button2.Name = "Button2" Me.Button2.Size = New System.Drawing.Size(80, 24) Me.Button2.TabIndex = 3 Me.Button2.Text = "Button2" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(360, 302) Me.Controls.Add(Me.Button2) Me.Controls.Add(Me.TextBox2) Me.Controls.Add(Me.TextBox1) Me.Controls.Add(Me.Button1) Me.Controls.Add(Me.TextBox3) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub #End Region Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click nomefich = TextBox1.Text fleitura = New FileStream(nomefich, FileMode.Open) FileOpen(fnum, "2" & nomefich, OpenMode.Binary) bleitura = New BinaryReader(fleitura) x = "" y = "" Do While True Try b = bleitura.Read Catch Exit Do End Try x = x & Format(b, "000") & " " y = y & Format((b Xor 18), "000") & " " c = (b Xor 18) FilePut(fnum, c) Loop bleitura.Close() FileClose(fnum) TextBox2.Text = x TextBox3.Text = y End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click fleitura = New FileStream("2" & nomefich, FileMode.Open) FileOpen(fnum, "3" & nomefich, OpenMode.Binary) bleitura = New BinaryReader(fleitura) Do While True Try b = bleitura.Read Catch Exit Do End Try c = (b Xor 18) FilePut(fnum, c) Loop bleitura.Close() FileClose(fnum) End Sub End Class este é o codigo .. agradecia imenso algum tipo de ajuda visto o prazo para entrega deste projecto estar a ficar apertado já.. cumps!
Tiago Salgado Posted June 1, 2006 at 07:54 PM Report #30633 Posted June 1, 2006 at 07:54 PM Se bem percebi...queres encriptar um .mp3 ?? com que finalidade ? :x
GpL Posted June 2, 2006 at 06:43 AM Author Report #30688 Posted June 2, 2006 at 06:43 AM N é so encriptar um mp3 .. é encriptar e desencriptar qualquer tipo de ficheiro .. com finalidade de criar um programa de encriptacao , ideia do meu prof de informatica para um projecto de basic este ano na disciplina dele ..
NuGuN Posted June 3, 2006 at 11:20 AM Report #30829 Posted June 3, 2006 at 11:20 AM Ja esprimentaste a fazer a espreencia com uma imagem pequena tipo um icon ou algu do genero, ou entao um txt grande. Digo istu porque podes estar a esceder a capacidade de alguma variavel quando abres uma imagem ou outro ficheiro, sinseramente n estou a ver qual a rasão desse problema 😄 Só mais uma coisa, quando dizes que ele não encripta nem desencripta os outros ficheiros queres dizer que ele da ero a meio?
GpL Posted June 4, 2006 at 11:33 AM Author Report #31001 Posted June 4, 2006 at 11:33 AM Sim, ja experimentei isso .. e o problema não me parece ser do tamanho .. Não dá erro a meio,cria o ficheiro supostamente desencriptado e encriptado na mesma mas só que o tamanho não tem nada a ver nem dá para abrir depois o desencriptado .. :s
NuGuN Posted June 4, 2006 at 04:56 PM Report #31061 Posted June 4, 2006 at 04:56 PM 😛 Gostava de te poder ajudar mas não sei mm o que pode ser, eu estou mais abituado ao VB6.... Podia ser do modo que estas a utilizar para abrir os ficheiros, mas se não me engano estas a abrilo em modo Binario que axu que é o mais correcto... Não desistas 🙂 e se consseguires resolver o prob diz qualquer coisa 😁 cumps
GpL Posted June 10, 2006 at 07:52 AM Author Report #32231 Posted June 10, 2006 at 07:52 AM Imports System.io Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Friend WithEvents abrir As System.Windows.Forms.OpenFileDialog Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents TextBox1 As System.Windows.Forms.TextBox Friend WithEvents Button2 As System.Windows.Forms.Button Friend WithEvents TextBox2 As System.Windows.Forms.TextBox <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.abrir = New System.Windows.Forms.OpenFileDialog Me.Button1 = New System.Windows.Forms.Button Me.TextBox1 = New System.Windows.Forms.TextBox Me.Button2 = New System.Windows.Forms.Button Me.TextBox2 = New System.Windows.Forms.TextBox Me.SuspendLayout() ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(200, 32) Me.Button1.Name = "Button1" Me.Button1.Size = New System.Drawing.Size(96, 24) Me.Button1.TabIndex = 0 Me.Button1.Text = "Abrir" ' 'TextBox1 ' Me.TextBox1.Location = New System.Drawing.Point(24, 32) Me.TextBox1.Name = "TextBox1" Me.TextBox1.Size = New System.Drawing.Size(160, 20) Me.TextBox1.TabIndex = 1 Me.TextBox1.Text = "" ' 'Button2 ' Me.Button2.Location = New System.Drawing.Point(16, 264) Me.Button2.Name = "Button2" Me.Button2.Size = New System.Drawing.Size(288, 24) Me.Button2.TabIndex = 2 Me.Button2.Text = "Copiar fixeiro" ' 'TextBox2 ' Me.TextBox2.Location = New System.Drawing.Point(24, 64) Me.TextBox2.Multiline = True Me.TextBox2.Name = "TextBox2" Me.TextBox2.ReadOnly = True Me.TextBox2.Size = New System.Drawing.Size(272, 192) Me.TextBox2.TabIndex = 3 Me.TextBox2.Text = "" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(320, 302) Me.Controls.Add(Me.TextBox2) Me.Controls.Add(Me.Button2) Me.Controls.Add(Me.TextBox1) Me.Controls.Add(Me.Button1) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub #End Region Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click With abrir If .ShowDialog() <> DialogResult.Cancel Then Me.TextBox1.Text = .FileName End If End With End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim fescrita, fleitura As filestream Dim bleitura As BinaryReader Dim bescrita As BinaryWriter Dim b As Byte Dim bts As String fleitura = New FileStream(Me.TextBox1.Text, FileMode.Open) fescrita = New FileStream("fcopiado.jpg", FileMode.CreateNew) bleitura = New BinaryReader(fleitura) bescrita = New BinaryWriter(fescrita) bleitura.BaseStream.Seek(0, SeekOrigin.Begin) bts = "" Do While True Try b = bleitura.ReadByte bts = bts & b Catch Exit Do End Try bescrita.Write(b) Loop TextBox2.Text = bts fleitura.Close() bleitura.Close() bescrita.Close() End Sub End Class Ja funca 🙂
NuGuN Posted June 11, 2006 at 01:17 PM Report #32393 Posted June 11, 2006 at 01:17 PM hehe 😉 Entao e qual era o problema??? cumps
vaurdan Posted July 10, 2006 at 11:46 AM Report #37315 Posted July 10, 2006 at 11:46 AM nao podes mostar o resultado final? http://www.neopt.org <- O meu blog xD
skin Posted July 10, 2006 at 02:54 PM Report #37361 Posted July 10, 2006 at 02:54 PM Me.Button2.Text = "Copiar ficheiro" e não Me.Button2.Text = "Copiar fixeiro" Our lives begin to end the day we become silent about things that matter - Martin Luther King
David Pintassilgo Posted July 10, 2006 at 06:27 PM Report #37397 Posted July 10, 2006 at 06:27 PM E então? já trabalha, ou não trabalha? Qual era o problema? cool stuffs to check. http://blog.zxcoders.com//
Asgorath Posted July 11, 2006 at 10:35 AM Report #37480 Posted July 11, 2006 at 10:35 AM Ola gpl, o teu problema é usares um simples XOR para encryptar ficheiros. Existe um namepace System.Security.Cryptography so para encryptacao, procura o seguinte site http://msdn2.microsoft.com/en-us/default.aspx por TripleDESCryptoServiceProvider class. Podias ter tambem usado o Code Snippets Manager do VS 2005. Jorge "The Dark Side Clouds Everthing. Impossible To See The Future Is."My rig: Intel Core 2 Quad Q9450 | abit IP35P | 4G Kingston 800 Mhz | XFX GeForce 9800 GX2 1G ddr3 | 2X WD5000AAJS 500Gb Sata 2 | PSU 600W || Caixa El-Diablo | Creative XMod
programadorvb6 Posted March 8, 2007 at 09:01 AM Report #87108 Posted March 8, 2007 at 09:01 AM como diz o colega : Asgorath "um simples XOR para encryptar ficheiros" [ ás vezes a instrução Xor dá problemas.. ( esta é a minha opinião ) ] Caso tenhas alguma dúvida me contacta: h2so4-programadorvb6@hotmail.com cump. até+ programadorvb6 ______________________________________________________________________________ Que minha coragem seja maior que meu medo e que minha força seja tão grande quanto minha fé.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now