Support Forums

Full Version: [C#] Encrypt/Decrypt BASE64
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Here's the source, Learn from it don't just Copy/Paste.

Code:
#region using
using System;
#endregion

namespace EncryptAndDecrypt
{
    #region class
    class Program
    {
        #region main
        static void Main(string[] args)
        {
        start:
            Console.Clear();
            Console.WriteLine("Would you like to encrypt or decrypt?");
            String crypt = Console.ReadLine();
            if (crypt == "encrypt")
            {
                Console.Clear();
                Console.WriteLine("Text to encrypt:");
                String toEncode = Console.ReadLine();


                byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncode);
                string returnvalue = System.Convert.ToBase64String(toEncodeAsBytes);
                Console.WriteLine(returnvalue);
                Console.WriteLine("\n\n\n");
                Console.WriteLine("Press Enter to continue...");
                Console.ReadLine();
                goto start;
            }
            if (crypt == "decrypt")
            {
                try
                {
                    Console.Clear();
                    Console.WriteLine("Text to decrypt:");
                    String decrypt = Console.ReadLine();
                    System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
                    System.Text.Decoder utf8Decode = encoder.GetDecoder();
                    byte[] todecode = Convert.FromBase64String(decrypt);
                    int charCount = utf8Decode.GetCharCount(todecode, 0, todecode.Length);
                    char[] decodedc = new char[charCount];
                    utf8Decode.GetChars(todecode, 0, todecode.Length, decodedc, 0);
                    string result = new String(decodedc);
                    Console.WriteLine(result);
                    Console.WriteLine("\n\n\n");
                    Console.WriteLine("Type 'Back' to go back to the start");
                    string read = Console.ReadLine();
                    if (read == "back")
                    {
                        goto start;
                    }

                }
                catch (Exception e)
                {
                    Console.WriteLine("\n\n");
                    Console.WriteLine("Error decoding");
                    Console.WriteLine("Type back to go back or info for info on the error.");
                    string readl = Console.ReadLine();
                    if (readl == "back")
                    {
                        goto start;
                    }
                    if (readl == "info")
                    {
                        Console.WriteLine("\n\n");
                        Console.WriteLine(e.ToString());
                        Console.ReadLine();
                        Console.WriteLine("\n\n");
                        Console.WriteLine("Type 'Back' to go back");
                        string readb = Console.ReadLine();
                        if (readb == "back")
                        {
                            goto start;
                        }
                    }
                }
        #endregion main
            }
    #endregion class

        }
    }
}

Have fun Smile
More information would be nice.
Well as i can see your account is closed.
So this thread should be closed?
(05-18-2010, 09:18 AM)//Pretext™ Wrote: [ -> ]More information would be nice.
Well as i can see your account is closed.
So this thread should be closed?

I was banned for a week due to posting a hacking tutorial.
Anyway i'm back now
Very nice Share Bro..>Did u code this???
(05-21-2010, 08:16 PM)Optiikzz™ Wrote: [ -> ]Very nice Share Bro..>Did u code this???

Yes xD i wouldn't rip it then post Tongue This is probably the first thing i made in C# when i went from VB.NET to C#
nice tut i like it. I like the fact people code C#. I <3 that language.
NIce share and good work Smile