CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2005
    Location
    algiers, Algeria
    Posts
    132

    Question 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

  2. #2
    Join Date
    Dec 2006
    Posts
    38

    Re: Need help to understand an algorithm

    Je ne parle pas francais!

  3. #3
    Join Date
    Oct 2003
    Location
    .NET2.0 / VS2005 Developer
    Posts
    7,104

    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
    "it's a fax from your dog, Mr Dansworth. It looks like your cat" - Gary Larson...DW1: Data Walkthroughs 1.1...DW2: Data Walkthroughs 2.0...DDS: The DataSet Designer Surface...ANO: ADO.NET2 Orientation...DAN: Deeper ADO.NET...DNU...PQ

  4. #4
    Join Date
    Mar 2007
    Location
    Argentina
    Posts
    579

    Re: Need help to understand an algorithm

    Quote Originally Posted by cjard View Post
    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)]

  5. #5
    Join Date
    Mar 2007
    Location
    Argentina
    Posts
    579

    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)]

  6. #6
    Join Date
    Dec 2005
    Location
    algiers, Algeria
    Posts
    132

    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
  •  





Click Here to Expand Forum to Full Width

Featured