|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
randomize encryption ..somebdy here can help me about randomize encryption, like for example i input my name angelito and i press the encrypt so the output would be a chr(ascii) , and when i re-input my name angelito and encrypt it the output of chr(ascii) would NOT be the same in the first chr(ascii) , so everytime i input the name angelito and encrypt it different chr(ascii) would appear, my problem is how about when i unload the form or close the program and i have this character >> "#ÞÑÎÝØïæ" << this one was encrypted .. And when i run the program and put it on the decrypt box the decrypted output was not the string angelito .. how about dat?? -- here's my work ... Option Explicit Dim random_stck As Integer Dim i As Integer Dim Cryptology As Integer Dim Cypher As String Dim cd As Integer Dim crypt1 As Integer Private Sub cmddecrypt_Click() D_CRYPT (Text1.Text) End Sub Private Sub cmdencrypt_Click() E_CRYPT (Text1.Text) End Sub Private Sub E_CRYPT(Text As String) random_stck = Int(Rnd * Len(Text)) Cryptology = Asc(Mid(Text, 1, 1)) + random_stck For i = 1 To Len(Text) Cryptology = Asc(Mid(Text, i, 1)) + random_stck Cypher = Cypher & Chr(Cryptology And 255) Next Text1.Text = Cypher Cypher = vbNullString End Sub Private Sub D_CRYPT(Text As String) For i = 1 To Len(Text) Cryptology = Asc(Mid(Text, i, 1)) - random_stck Cypher = Cypher & Chr(Cryptology And 255) Next Text2.Text = Cypher Cypher = vbNullString End Sub Private Sub Form_Load() Randomize End Sub it's only on the form i didn't put it on any modules ... On 10 May 2007 19:09:11 -0700, angelito tan
<diamond_shoe1***@yahoo.com> wrote: >this is tough,, and i guess i'm in the right site, i wonder is there <snip>>somebdy here can help me about randomize encryption, like for example >i input my name angelito and i press the encrypt so the output would >be a chr(ascii) , and when i re-input my name angelito and encrypt it >the output of chr(ascii) would NOT be the same in the first >chr(ascii) , so everytime i input the name angelito and encrypt it >different chr(ascii) would appear, my problem is how about when i >unload the form or close the program and i have this character >> >"#=DE=D1=CE=DD=D8=EF=E6" << this one was encrypted .. And when i run the pr= >ogram and >put it on the decrypt box the decrypted output was not the string >angelito .. how about dat?? I looked into that recently, my version produces a load of numbers, but I think you are going down the same path. The idea is to store a 'seed' for VB's random number generator so one can reproduce the same sequence of 'random' numbers Option Explicit ' Encrypt/Decrypt Password ' Using seeded Random Number Series ' JF 4th April 2007 Private Sub Command1_Click() Label1.Caption = LF_Encrypt(Text1.Text) End Sub Private Sub Command2_Click() Label2.Caption = LF_Decrypt(Label1.Caption) End Sub Private Function LF_Encrypt$(P$) Dim Seed&, S$, L9&, N& Dim Result$ Seed = Timer Rnd -1 ' Force same sequence Randomize Seed For L9 = 1 To Len(P$) N& = Int(Rnd * 100) + 1 N& = N& * Asc(Mid$(P$, L9, 1)) Result$ = Result$ + Str$(N&) Next LF_Encrypt$ = Trim$(Str$(Seed)) + Result$ End Function Private Function LF_Decrypt$(P$) Dim L9&, N& Dim A$() Dim Result$ Call LS_Split(P$, A$()) Rnd -1 ' Force same sequence Randomize Val(A$(0)) For L9 = 1 To UBound(A$()) N& = Int(Rnd * 100) + 1 Result$ = Result$ + Chr$(Val(A$(L9)) / N&) Next LF_Decrypt = Result$ End Function ' --- No Split() in VB5 Private Sub LS_Split(ByVal P$, A$()) Dim Start&, Pos&, Max& ReDim A$(100) Max = -1 P$ = P$ + " " Start = 1 Pos = 1 While Pos > 0 Pos = InStr(Start, P$, " ") If Pos Then Max = Max + 1 A$(Max) = Mid$(P$, Start, Pos - Start) Debug.Print (A$(Max)) Start = Pos + 1 End If Wend ReDim Preserve A$(Max) End Sub Private Sub Form_Load() Command1.Caption = "Encrypt" Command2.Caption = "Decrypt" End Sub waaa ,, this code is what i'm looking for thanks man, thank you xo
much,, it really helps a lot ^^ .. *** Sent via Developersdex http://www.developersdex.com *** In addition to what J French said, your decrypt routine does not set the
value of random_stck so it will always be either zero or the last value from the encrypt routine. I also don't know if the VB random number generator can be sure to always produce the same sequence (given the same seed) on every platform and under every OS. My main concern is the hardware random number generators finding their way into newer microprocessors which may be more supported by later OS's. I have used similar techniques but I use a sequence generator to produce a set of pseudo-random numbers from a given seed - much like the random generator but I am in control of the whole thing. Regards Dave O. "angelito tan" <diamond_shoe1***@yahoo.com> wrote in message this is tough,, and i guess i'm in the right site, i wonder is therenews:1178849351.765259.75670@u30g2000hsc.googlegroups.com... somebdy here can help me about randomize encryption, like for example i input my name angelito and i press the encrypt so the output would be a chr(ascii) , and when i re-input my name angelito and encrypt it the output of chr(ascii) would NOT be the same in the first chr(ascii) , so everytime i input the name angelito and encrypt it different chr(ascii) would appear, my problem is how about when i unload the form or close the program and i have this character >> "#ÞÑÎÝØïæ" << this one was encrypted .. And when i run the program and put it on the decrypt box the decrypted output was not the string angelito .. how about dat?? -- here's my work ... Option Explicit Dim random_stck As Integer Dim i As Integer Dim Cryptology As Integer Dim Cypher As String Dim cd As Integer Dim crypt1 As Integer Private Sub cmddecrypt_Click() D_CRYPT (Text1.Text) End Sub Private Sub cmdencrypt_Click() E_CRYPT (Text1.Text) End Sub Private Sub E_CRYPT(Text As String) random_stck = Int(Rnd * Len(Text)) Cryptology = Asc(Mid(Text, 1, 1)) + random_stck For i = 1 To Len(Text) Cryptology = Asc(Mid(Text, i, 1)) + random_stck Cypher = Cypher & Chr(Cryptology And 255) Next Text1.Text = Cypher Cypher = vbNullString End Sub Private Sub D_CRYPT(Text As String) For i = 1 To Len(Text) Cryptology = Asc(Mid(Text, i, 1)) - random_stck Cypher = Cypher & Chr(Cryptology And 255) Next Text2.Text = Cypher Cypher = vbNullString End Sub Private Sub Form_Load() Randomize End Sub it's only on the form i didn't put it on any modules ... This is a good technique Angelito. I have a few tips though...
-- Always use a byte-array for the encrypted String data, never another String. Trying to use a String for the encrypted data puts you at risk of generating invalid Unicode characters, and falling foul of locale differences (e.g. different ANSI character sets implied by Chr/Asc if the decryption is done in a different location to the encryption). -- When inserting random data into your data, prior to encrypting it, avoid unusual or non-printable characters, and avoid inserting them at regular intervals. Someone who was seriously trying to break your encryption would easily recognise such a pattern. Better to insert pieces of real text taken from some other source, and insert it at deterministic but non-regular places. Tony Proctor "angelito tan" <diamond_shoe1***@yahoo.com> wrote in message this is tough,, and i guess i'm in the right site, i wonder is therenews:1178849351.765259.75670@u30g2000hsc.googlegroups.com... somebdy here can help me about randomize encryption, like for example i input my name angelito and i press the encrypt so the output would be a chr(ascii) , and when i re-input my name angelito and encrypt it the output of chr(ascii) would NOT be the same in the first chr(ascii) , so everytime i input the name angelito and encrypt it different chr(ascii) would appear, my problem is how about when i unload the form or close the program and i have this character >> "#ÞÑÎÝØïæ" << this one was encrypted .. And when i run the program and put it on the decrypt box the decrypted output was not the string angelito .. how about dat?? -- here's my work ... Option Explicit Dim random_stck As Integer Dim i As Integer Dim Cryptology As Integer Dim Cypher As String Dim cd As Integer Dim crypt1 As Integer Private Sub cmddecrypt_Click() D_CRYPT (Text1.Text) End Sub Private Sub cmdencrypt_Click() E_CRYPT (Text1.Text) End Sub Private Sub E_CRYPT(Text As String) random_stck = Int(Rnd * Len(Text)) Cryptology = Asc(Mid(Text, 1, 1)) + random_stck For i = 1 To Len(Text) Cryptology = Asc(Mid(Text, i, 1)) + random_stck Cypher = Cypher & Chr(Cryptology And 255) Next Text1.Text = Cypher Cypher = vbNullString End Sub Private Sub D_CRYPT(Text As String) For i = 1 To Len(Text) Cryptology = Asc(Mid(Text, i, 1)) - random_stck Cypher = Cypher & Chr(Cryptology And 255) Next Text2.Text = Cypher Cypher = vbNullString End Sub Private Sub Form_Load() Randomize End Sub it's only on the form i didn't put it on any modules ... thnk you all for the participating this thread i really appreciate it,
^^ thnks jeff, dave, tony for helping .. just one last question .. in the code that jeff shared , this one bothering me, not that much but i nid to be sure .. this one ' --- No Split() in VB5 Private Sub LS_Split(ByVal P$, A$()) Dim start&, pos&, max& ReDim A$(100) Max = -1 P$ = P$ + " " Start = 1 Pos = 1 While Pos > 0 Pos = InStr(Start, P$, " ") If Pos Then Max = Max + 1 A$(Max) = Mid$(P$, Start, Pos - Start) Debug.Print (A$(Max)) Start = Pos + 1 End If Wend ReDim Preserve A$(Max) End Sub u say no vb split in vb5 so u mean this code is subtitute in vbsplit on vb6?? or it's the same pattern that vbsplit using in vb6? thanks for sharing ^^ *** Sent via Developersdex http://www.developersdex.com *** On Fri, 11 May 2007 03:01:18 -0700, angelito tan
<diamond_shoe1***@yahoo.com> wrote: <snip> >u say no vb split in vb5 so u mean VB5 does not have the Split Function, it also cannot return String>this code is subtitute in vbsplit on vb6?? > >or it's the same pattern that vbsplit using in vb6? >thanks for sharing ^^ Arrays as the result of a function - so I wrote something similar that does the same job I wonder if Dave's point about hardware Random Number generation is relevant to VB - personally I think it unlikely that VB uses anything other than its own code, but he has got a point, it would be very difficult reproducing the algorithm in another language. |
|||||||||||||||||||||||