Click here to Skip to main content
15,918,330 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need to Convert the following cryptFunction in VB to C#
This is the VB code :-
Private Function cryptEntry(s$) As String

    Dim k$, r$, i%

    k = "§$=)%;:-:*(""§%""§=("             

    r = Left$(s + String(15, Chr$(32)), 15)           

    For i = 1 To Len(r)

        Mid$(r, i, 1) = Chr$(Asc(Mid$(r, i, 1)) Xor Asc(Mid$(k, i, 1)))

    Next i

    cryptEntry = r

End Function


What I have tried:

This is what I tried in C#

private string cryptEntry(string s)
       {
           string k = "", r = "";
           k = "§$=)%;:-:*(""§%""§=(";
           string insideString = "", concatString = "", leftString = "";
           insideString = new String((char)32, 15);
           concatString = String.Concat(s, insideString);
           leftString = concatString.Substring(0, 15);
           r = leftString;
           for (int i = 1; i < r.Length; i++)
           {
               string rmid = r.Substring(i, 1);
               string kmid = k.Substring(i, 1);
               byte[] rmidascii = Encoding.ASCII.GetBytes(rmid);
               byte[] kmidascii = Encoding.ASCII.GetBytes(kmid);
              // rmid = (rmidascii != kmidascii);
            }
           return r;
       }


I don't know the equivalent XOR operator in C#. My guess it would be !=
Posted
Updated 18-Jun-19 4:55am
v2
Comments
Richard MacCutchan 18-Jun-19 9:03am    
That code is confusing, and it is not clear what you are trying to do. Please edit your question and show just the VB code first, then just the C# code, and explain what inputs you are using and what outputs it should produce.
Priya Karthish 18-Jun-19 9:32am    
I have edited the question
F-ES Sitecore 18-Jun-19 9:06am    
Of course it displays nothing, you are creating a string with 15 spaces, what are you expecting it to display? :) The original code was adding the spaces after the "s" variable, but your code isn't.
Priya Karthish 18-Jun-19 14:45pm    
Thank you.

Quote:
I don't know the equivalent XOR operator in C#. My guess it would be !=
Don't guess, read the documentation: C# operators - C# reference | Microsoft Docs[^].
 
Share this answer
 
Comments
Maciej Los 18-Jun-19 11:18am    
Short And To The Point!
Try:
C#
string input = "Hello";
string output = $"{input,-15}";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900