-
February 17th, 2009, 10:17 AM
#1
Need help to understand an algorithm
Hi all, i have this algorithm for decrypt a message how i can translate the functions in red to c#
Code:
'CIPHER.CLS
Option Explicit
Private msKeyString As String
Private msText As String
'~~~.KeyString
'Une chaîne (clé) utilisée dans l'encryptage et le décryptage
Public Property Let KeyString(sKeyString As String)
msKeyString = sKeyString
Initialize
End Property
'~~~.Text
'Ecrit le texte Ã* encrypter ou décrypter
Public Property Let Text(sText As String)
msText = sText
End Property
'Lit le texte qui a été encrypté ou décrypté
Public Property Get Text() As String
Text = msText
End Property
'~~~.DoXor
'Méthode d'encryptage ou de décryptage par ou exclusif
Public Sub DoXor()
Dim nC As Integer
Dim nB As Integer
Dim lI As Long
lI = 1
For lI = 1 To Len(msText)
nC = Asc(Mid(msText, lI, 1))
nB = Int(Rnd * 256)
Mid(msText, lI, 1) = Chr(nC Xor nB)
Next lI
'MsgBox msText
End Sub
'~~~.Stretch (extension)
'Conversion de n'importe quelle chaîne en chaîne imprimable
'et visualisable
Public Sub Stretch()
Dim nC As Integer
Dim lI As Long
Dim lJ As Long
Dim nK As Integer
Dim lA As Long
Dim sB As String
lA = Len(msText)
sB = Space(lA + (lA + 2) \ 3)
For lI = 1 To lA
nC = Asc(Mid(msText, lI, 1))
lJ = lJ + 1
Mid(sB, lJ, 1) = Chr((nC And 63) + 59)
Select Case lI Mod 3
Case 1
nK = nK Or ((nC \ 64) * 16)
Case 2
nK = nK Or ((nC \ 64) * 4)
Case 0
nK = nK Or (nC \ 64)
lJ = lJ + 1
Mid(sB, lJ, 1) = Chr(nK + 59)
nK = 0
End Select
Next lI
If lA Mod 3 Then
lJ = lJ + 1
Mid(sB, lJ, 1) = Chr(nK + 59)
End If
msText = sB
'MsgBox msText
End Sub
'~~~.Shrink (Compression)
'Inverse de la méthode Décompactage (Stretch);
'le résultat peut contenir n'importe quelle valeur d'octet (0-255)
Public Sub Shrink()
Dim nC As Integer
Dim nD As Integer
Dim nE As Integer
Dim lA As Long
Dim lB As Long
Dim lI As Long
Dim lJ As Long
Dim lK As Long
Dim sB As String
On Error GoTo Errora
lA = Len(msText)
lB = lA - 1 - (lA - 1) \ 4
sB = Space(lB)
For lI = 1 To lB
lJ = lJ + 1
nC = Asc(Mid(msText, lJ, 1)) - 59
Select Case lI Mod 3
Case 1
lK = lK + 4
If lK > lA Then lK = lA
nE = Asc(Mid(msText, lK, 1)) - 59
nD = ((nE \ 16) And 3) * 64
Case 2
nD = ((nE \ 4) And 3) * 64
Case 0
nD = (nE And 3) * 64
lJ = lJ + 1
End Select
Mid(sB, lI, 1) = Chr(nC Or nD)
Next lI
msText = sB
'MsgBox sB
Exit Sub
Errora:
'msText = ""
End Sub
'Initialise les nombres aléatoires en utilisant la chaîne clé
Private Sub Initialize()
Dim nI As Double
Randomize Rnd(-1)
For nI = 1 To Len(msKeyString)
Randomize Rnd(-Rnd * Asc(Mid(msKeyString, nI, 1)))
Next nI
End Sub
-
February 17th, 2009, 07:06 PM
#2
Re: Need help to understand an algorithm
Je ne parle pas francais!
-
February 17th, 2009, 08:11 PM
#3
Re: Need help to understand an algorithm
Tu peut parle un peut! Sufficient pour recommender essayer un VB.NET a C# traducteur?
Aussi, depuis quand il faut necessaire pour avoir les codes-sources plus facile (comme ici) en Anglais?!
Code:
'meilleur
public void DoXor(){
int nC, nB;
StringBuilder sb = new StringBuilder();
foreach char c in msText
sb.Append((char)(((int)c) ^ (Rnd * 256)) );
msText = sb.ToString();
}
I think that's correct
-
February 17th, 2009, 08:30 PM
#4
Re: Need help to understand an algorithm
Originally Posted by cjard
Tu peut parle un peut! Sufficient pour recommender essayer un VB.NET a C# traducteur?...
try:
http://www.developerfusion.com/tools.../csharp-to-vb/
[Vb.NET 2008 (ex Express)]
-
February 17th, 2009, 08:35 PM
#5
Re: Need help to understand an algorithm
frenchs have good math, so probably also have good code.
try google translator
[Vb.NET 2008 (ex Express)]
-
February 18th, 2009, 03:07 AM
#6
Re: Need help to understand an algorithm
Hi all, i am not french !! and thanks for all
Last edited by ledaker; February 18th, 2009 at 03:40 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|