Results 1 to 2 of 2
  1. #1
    Departure's Avatar
    Join Date
    Nov 2010
    Gender
    male
    Posts
    818
    Reputation
    125
    Thanks
    1,785
    My Mood
    Doh

    Caesar/ROT String Encryption

    Well I know some people are wanting to encrypt there strings in there hacks, I dont code in C++ and I am just learning C#, One of my projects in C# for learning purposes was to convert some of my Delphi Encryptions, Here you have a C# Caesar/ROT encryption, don't laugh at my C# coding as im just learning but this seems to run very good and maybe it might help the guys who write in C++, It should be easyer to read than Delphi due to the similarties between C++ and C#

    //Edit
    Decided to include the whole class which also include the Vigener Cipher(uses a key). I personally would still convert the ROT cipher for your string encryption in C++ for the hacks.

    Code:
    /* 
     Class  : StringCrypt.cs
     Aurthor: Departure
     Url    : www.Cheesydoodle.com 
     Info:
        Encrypt Strings with Vigenere Cipher and ROT Cipher(Caesar Cipher, Rot13 ect..)
        Based on information from wiki
     */
    
    internal class StringCrypt
        {
            public static string Vigenere(string sSource, string sKey, int iTableSize = 94, bool bDecrypt = false)
            {
                //Variables
                int i = 32;
                int iPosText;
                int iPosKey;
                string sTable = "";
                string sResult = "";
    
                //Create Table
                while (i < (iTableSize + 32))
                {
                    sTable +=  ((char)i);
                    i++;
                }
    
                //Make Key same size as Cipher
                while (sSource.Length >= sKey.Length)
                {
                    sKey = string.Concat(sKey, sKey);
                }
    
                //Vigenere Routine
                i = 0;
                while (i <= (sSource.Length - 1))
                {
                    if (sTable.IndexOf(sSource[i]) == -1)
                        sResult += sSource[i];
                    else
                    {
                        iPosText = sTable.IndexOf(sSource[i]);
                        iPosKey = sTable.IndexOf(sKey[i]);
                        if (bDecrypt)
                            sResult += sTable[(((iPosText + iTableSize) - iPosKey) % iTableSize)];
                        else
                            sResult += sTable[((iPosText + iPosKey) % iTableSize)];
                    }
                    i++;
    
                }
    
                return sResult;
    
            }
    
            public static string Caesar(string sSource, int iKey, bool bDecrypt = false)
            {
                //Variables
                string sResult = "";
                string sTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                int iPosText;
                int i;
    
                //Convert to Uppercase
                sSource = sSource.ToUpper();
    
                //Caesar Routine
                i = 0;
                while (i <= (sSource.Length - 1))
                {
                    if (sTable.IndexOf(sSource[i]) == -1)
                        sResult += sSource[i];
                    else
                    {
                        iPosText = sTable.IndexOf(sSource[i]);
                        if (bDecrypt)
                            sResult += sTable[(((iPosText + sTable.Length) - iKey) % sTable.Length)];
                        else
                            
                        sResult += sTable[((iPosText + iKey) % sTable.Length)];
                    }
                    i++;
                }
    
                return sResult;
    
            }
    
            public static string ROT13(string sSource)
            {
                return Caesar(sSource, 13, false);
            }
        }

    Suggestions would be to change the sTable to include all readable alphabet Letters and numbers, even include special chars also this is a Rotation of 13 change this modifying this line
    return Caesar(sSource, 13, false); change 13 to how ever many positions, to decrypt the encrypted string just set this line to True
    Last edited by Departure; 02-25-2011 at 09:34 PM.

  2. The Following 3 Users Say Thank You to Departure For This Useful Post:

    GodHack2 (02-25-2011),Stephen (02-28-2011),wolffang0000 (02-26-2011)

  3. #2
    Stephen's Avatar
    Join Date
    Jun 2009
    Gender
    male
    Location
    Engine.exe
    Posts
    4,690
    Reputation
    184
    Thanks
    1,147
    My Mood
    Aggressive
    If you want me to post an XOR encryption + the .html file it uses to generate it. I got tired of using the HTML for it and just converted that to C++ and made a simple utility in a console app.