Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[C#] Encrypt/Decrypt BASE64
#1
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
Reply
#2
More information would be nice.
Well as i can see your account is closed.
So this thread should be closed?
Reply
#3
(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
Reply
#4
Very nice Share Bro..>Did u code this???
[Image: OGForumsbanner.png]
Reply
#5
(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#
Reply
#6
nice tut i like it. I like the fact people code C#. I <3 that language.
Reply
#7
NIce share and good work Smile
Returning to SF / HF. Long story Tongue
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Encrypt String using x509Certificate private Key wih RSA jeffstan 0 2,442 01-26-2014, 04:18 PM
Last Post: jeffstan
  [C#] BitCrypt - Visually Encrypt Binary Data (Bitmap Structures) AceInfinity 4 2,038 08-01-2012, 05:14 PM
Last Post: AceInfinity
  [request] how to encrypt server / client packets {C#,C++,VB.NET or Delphi} KoBE 2 2,544 07-02-2011, 08:11 AM
Last Post: besimbicer
  [Source] Encrypt/Decrypt a string using Data Encryption Standard (DES) algorithm euverve 0 2,018 05-12-2011, 08:43 PM
Last Post: euverve
  [TUT]Encrypt Your Infos[TUT] ThePrinCe 2 1,283 02-27-2011, 12:29 AM
Last Post: thanasis2028

Forum Jump:


Users browsing this thread: 3 Guest(s)