Decrypt a String - CSharp System

CSharp examples for System:String Base

Description

Decrypt a String

Demo Code

// Redistribution and use in source and binary forms, with or without modification,
using System.Text;
using System;//ww  w. j a  v  a  2  s. co m

public class Main{
        public static string Decrypt(string text)
        {
            string key = "123321Sc9FVpwerrw8RsdfZn";

            byte[] decodedBytes = Convert.FromBase64String(text);
            string decodedText = System.Text.Encoding.UTF8.GetString(decodedBytes, 0, decodedBytes.Length);

            var result = new StringBuilder();

            for (int c = 0; c < decodedText.Length; c++)
                result.Append((char)((uint)decodedText[c] ^ (uint)key[c % key.Length]));

            return result.ToString();
        }
}

Related Tutorials