Home » Source Code » M2 a proprietary encryption algorithm

M2 a proprietary encryption algorithm

maninwest
2015-03-02 04:54:07
The author
View(s):
Download(s): 2
Point (s): 1 
Category Category:
EncryptionEncryption C SharpC#

Description

Translated by maninwest@Codeforge Author:Michael_Jacobsen@CodeProject
This encryption class that is very easy to implement and use. If you're in need of a method for encrypting strings like passwords, cardnumbers etc. etc, this is a fast, simpel and secure way of doing so. As long as you don't expose your encryption key you should be safe. I recommended that you use a key with a minimum length of 12 characters which contains both upper and lower case letters.
Please read the section "The inner workings of the algorithm" if you want to study how I designed it, and also to maybe alleviate any safety concerns you might be having.
Also feel free to throw any comment in the debate section at the bottom of the screen.
 
Using the code


First insert the class from the downloaded source code inside your name space. You will then be abel to instantiate objects of my class.
Encryption:
The following code block is a short example of how to encrypt the string variableYourTextStringwith the encryption key variableYourEncryptionKey 

M2encryption.Key = YourEncryptionKey;
M2encryption objEncrypt = new M2encryption();
objEncrypt.ClearTekst = YourTextString; 
objEncrypt.Encrypt(); if (objEncrypt.errorState != -2) {       
    MessageBox.Show(objEncrypt.EncryptedTekst);
}

Check the propertyobjEncrypt.errorStatefor errors before proceeding in your code.
errorState-1:
This means the text encrypted contained characters outside of the Ascii range. These characters were changed to "?" in the cleartext before encryption
errorState-2:
No encryption key was provided. Then encryption process was aborted.
Decryption:
M2encryption.Key = YourEncryptionKey;
M2encryption objEncrypt = new M2encryption();
objEncrypt.EncryptedTekst = YourTextString; 
objEncrypt.Decrypt(); if (objEncrypt.errorState != -2) {       
    MessageBox.Show(objEncrypt.ClearTekst);
}

Randomization
Setting the propertyRandomizationto true, will produce a different cipher-text by the same key and clear text when run multiple times.
M2encryption.Randomization = true;

Fastmode
Setting the propertyFastmodeto true will make the encryption/decryption process faster but also a little less secure. If you're encrypting small strings like passwords, card numbers etc. etc. you should not do it in Fastemode, but if you're encrypting documents like several A4-pages long you should do it in Fastmode.Fastmode= false is default.
Notice! Decryption should be done in the same mode it was encrypted in.
M2encryption.Fastmode = true;

 
The inner workings of the algorithm


Outer and inner loops



The algorithm consist of an outer and inner loop. The outer loop iterates the rounds, the inner loop iterates the entire clear text one character at a time.


Self-mutating outer and inner keys


The self-mutating inner key

This key is used for encryption in the inner encryption process. Each letter of the key is used for encrypting the letter in the respective position in the clear text. When the key reaches the end of it's string, the process will continue in a new mutated version of the key. This process will continue until the entire clear text string has been encrypted. See Fig1 underneath for an illustration of this process. The self-mutating inner key is marked in blue.


Fig1. The key pattern in the above illustration will never repeat itself throughout the entire encryption process
 
The self-mutating outer  key
The self-mutating outer key is initiated from then key entered by the user. This key is used in the outer loop and is self-mutated in the beginning of each round. The purpose of the key is to generate a unique mapping array for each round and to initiate the self-mutating inner key in these rounds. The mapping array is used by the encryption process in the inner loop.
Example of the key self-mutating in a 6 rounds iteration:




The function shuffleArr() is an algorithm I wrote that takes the outer self-mutating key as input. Based on the key it will lay out the mapping numbers in "random like" order in the arrayint[]map. Every time this function is called the key will self-mutate thus creating a new unique mapping array each time.
Function shuffleArr():

private void shuffleArr(int state){

    int keyStep = 0;
    byte keyChar;
    bool emptyFound;
    int retning = 1;
    long refIndex = 1;
    double floatValue;
    int intPart;
    double fraPart;

    mutKey_o = selfMutateKey(mutKey_o, 3, state,1);
    for (int i = 0; i < 95; i++) map[i] = 0; //nulstil arr
    for (int i = 1; i < 96; i++)
    {
        if (retning == 1) retning = 0;
        else retning = 1;

        //håndter key
        if (keyStep > mutKey_o.Length - 1) keyStep = 0;

        keyChar = (byte)mutKey_o[keyStep];
        refIndex = i + (int)keyChar;

        if (refIndex > 95)
        {
            if (refIndex - 95 <= 95) refIndex = refIndex - 95;
            else
            {
                floatValue = refIndex / 95.0;
                intPart = (int)floatValue;
                fraPart = floatValue - intPart;
                if (fraPart == 0.0) fraPart = 1.0;
                refIndex = Convert.ToInt32(95 * fraPart);
            }
        }

        refIndex--; //pga arr 0- 94
        if (map[refIndex] == 0) map[refIndex] = i;
        else
        {
            emptyFound = false;
            do
            {
                if (retning == 1)
                {
                    refIndex++;
                    if (refIndex > 94) refIndex = 0;
                    if (map[refIndex] == 0)
                    {
                        map[refIndex] = i;
                        emptyFound = true;
                    }
                }
                else
                {
                    refIndex--;
                    if (refIndex < 0) refIndex = 94;
                    if (map[refIndex] == 0)
                    {
                        map[refIndex] = i;
                        emptyFound = true;
                    }
                }

            } while (emptyFound == false);
        }

        keyStep++;
    }

    for (int i = 0; i < 95; i++)
    {
        for (int k = 0; k < 95; k++)
        {
            if (map[k] == i + 1)
            {
                mapRev[i] = (k + 1);
                break;
            }
        }
    } 
}

The inner loop encryption process


Step 1:
The entire text will be put through the function chainChangeChars().
The text is scanned from the start of the string to the end of the string and back again. Each letter in the text is change according to it's left side neighbour (or right side when going back). Thus if one letter changes anywhere in the text, every single letter will be changed accordingly in a chain reaction. Each changed letter is then remapped through the mapping arrayint[]map
This is the formula i developed to solve the problem:
Example text "ABCD"
A is B's left side neighbour

 
And the reverse:

Then remapped:
Y = map[X]
And finnaly:
B is then replaced by Y
The text becomes "AYCD" (where Y is a variable holding the actual letter)
The original B is now stored inside Y and can be reversed by Y and A.
Step 2:
This step is the beginning of a process that will change every character in the text according to the self-mutating inner key as illustrated in fig1. This step plus every following steps is per character in the inner loop.
The first step in this process is to generate a seed. For each letter to be changed, the decimal ascii value of the next letter in the key is accumulated in the variabelseedC. See the first line of code in the code bloc below:
seedC = seedC + (byte)Convert.ToChar(key[keyIndexC]);
keyIndexC++; if (keyIndexC > lenKey - 1)
{
    keyIndexC = 0;
    mutKey_i = selfMutateKey(key,2,1,2);
}

Step 3:
Generating a reference index number.
The seed from step 2 is now used as input to the function createRefIndex()
In this function seed is put through my simpel formula:
I divide seed by 95
Change the integer part to of the decimal number to 0
And multiply the result by 95
I code it looks like this:
refIndex = seed; if (refIndex > 95)
{ if (refIndex - 95 <= 95) 
        refIndex = refIndex - 95; else {
        floatValue = refIndex / 95.0;
        intPart = (int)floatValue;
        fraPart = floatValue - intPart; if (fraPart == 0.0) fraPart = 1.0;
        refIndex = Convert.ToInt32(95 * fraPart);
    }
}

The resultantrefIndexwill always be an integer number  in the range [1 - 95] no matter how large seed is.
Step 4:
In this final step the character is change to it's final character in the cipher-text for this round.
The character's index is added to therefIndex-1
The final result is then remapped through the mapping arrayint[]map.
tegnChanged = tegn + (refIndex - 1); if (tegnChanged > 95) tegnChanged = tegnChanged - 95;
tegnChanged = map[tegnChanged - 1];
 

The complete sourcecode
public class M2encryption
{ /* M2 encryption class

* (M)ichaels (2)nd encryption algoritme. Blended words


* A simpel encryption algorithm for encrypting plain text.

* Can by useful for encrypting passwords, messages or data stored in a DB or file etc. etc. 
*  
* This algoritme is limited to encrypting ASCII characters in the ASCII range from 32 to 126 (dec)
* If ClearTekst contains chars outside of this range errorState will be -1

* If you encrypt in Fastmode you also have to decrypt in fastmode!


* By Michael Jacobsen
* Lyngby 12th of Febuary 2015.
*/ System.Text.Encoding ascii = System.Text.Encoding.ASCII; public static string Key = ""; public static Boolean Randomization = false; public static Boolean Fastmode = false; public string ClearTekst; public string EncryptedTekst; public int errorState=0; private int[] map = new int[95]; private int[] mapRev = new int[95]; private long seedC = 0; private long seedK = 0; private int keyIndexC = 0; private int keyIndexK = 0; private string mutKey_o; //outer  private string mutKey_i; //inner  private byte changeByte(byte byteChar, int keyLen, long tekstLen, string mode)
{ int intRef; byte changedChar; long seed;


intRef = ((int)byteChar) - 31; if (mode == "C") {
genSeedC(mutKey_i, keyLen, tekstLen);
seed = seedC;
} else { 
genSeedK(mutKey_i, keyLen, tekstLen);
seed = seedK;
}
changedChar = (byte)(changeChar(intRef, seed) + 31); return changedChar;
} private byte changeByteRev(byte byteChar, int keyLen, long tekstLen, string mode)
{ int intRef; byte changedChar; long seed;


intRef = ((int)byteChar) - 31; if (mode == "C")
{
genSeedC(mutKey_i, keyLen, tekstLen);
seed = seedC;
} else {
genSeedK(mutKey_i, keyLen, tekstLen);
seed = seedK;
}
changedChar = (byte)(changeCharRev(intRef, seed) + 31); return changedChar;
} private int createRefIndex(long seed)
{ long refIndex = 1; double floatValue; int intPart; double fraPart;


refIndex = seed; if (refIndex > 95)
{ if (refIndex - 95 <= 95) 
refIndex = refIndex - 95; else {
floatValue = refIndex / 95.0;
intPart = (int)floatValue;
fraPart = floatValue - intPart; if (fraPart == 0.0) fraPart = 1.0;
refIndex = Convert.ToInt32(95 * fraPart);
}
} return (int)refIndex; 
} private int changeChar(int tegn, long seed)
{ int refIndex; int tegnChanged;


refIndex = createRefIndex(seed);
tegnChanged = tegn + (refIndex - 1); if (tegnChanged > 95) tegnChanged = tegnChanged - 95;
tegnChanged = map[tegnChanged - 1]; return tegnChanged;
} private int changeCharRev(int tegn, long seed)
{ int refIndex; int tegnChanged;


tegn = mapRev[tegn - 1];
refIndex = createRefIndex(seed);
tegnChanged = tegn - (refIndex - 1); if (tegnChanged < 0) tegnChanged = tegnChanged * (-1); if (tegn < refIndex) tegnChanged = 95 - tegnChanged; return tegnChanged;
} private string chainChangeChars(string tekst)
{ char tegn1; char tegn2; char tegn3; for (int i = 0; i < tekst.Length - 1; i++)
{
tegn1 = Convert.ToChar(tekst[i]);
tegn2 = Convert.ToChar(tekst[i+1]);


tegn3 = (char)linkTegn(tegn1, tegn2);
tekst = tekst.Substring(0, i + 1) + tegn3 + tekst.Substring(i + 2, tekst.Length - (i + 2));
} for (int i = tekst.Length - 2; i > -1; i--)
{
tegn1 = Convert.ToChar(tekst[i+1]);
tegn2 = Convert.ToChar(tekst[i]);
tegn3 = (char)linkTegn(tegn1, tegn2);
tekst = tekst.Substring(0, i) + tegn3 + tekst.Substring(i + 1, tekst.Length - (i + 1));
} return tekst;
} private string chainChangeCharsRev(string tekst)
{ char tegn1; char tegn2; char tegn3; for (int i = 0; i < tekst.Length - 1; i++)
{
tegn1 = Convert.ToChar(tekst[i+1]);
tegn2 = Convert.ToChar(tekst[i]);
tegn3 = (char)linkTegnRev(tegn1, tegn2);
tekst = tekst.Substring(0, i) + tegn3 + tekst.Substring(i + 1, tekst.Length - (i + 1));
} for (int i = tekst.Length - 2; i > -1; i--)
{
tegn1 = Convert.ToChar(tekst[i]);
tegn2 = Convert.ToChar(tekst[i + 1]);
tegn3 = (char)linkTegnRev(tegn1, tegn2);
tekst = tekst.Substring(0, i + 1) + tegn3 + tekst.Substring(i + 2, tekst.Length - (i + 2));
} return tekst;
} private byte linkTegn(int tegn1, int tegn2)
{ int forskydning; int tegnRes;


forskydning = tegn1 - 32;
tegnRes = tegn2 + forskydning; if (tegnRes > 126) tegnRes = tegnRes - 95; return (byte)((map[tegnRes - 32]) + 31);
} private byte linkTegnRev(int tegn1, int tegn2)
{ int forskydning; int tegnRes;


tegn2 = (mapRev[(tegn2 - 32)] + 31);
forskydning = tegn1 - 32;
tegnRes = tegn2 - forskydning; if (tegnRes < 32) tegnRes = tegnRes + 95; return (byte)tegnRes;
} private void shuffleArr(int state){ int keyStep = 0; byte keyChar; bool emptyFound; int retning = 1; long refIndex = 1; double floatValue; int intPart; double fraPart;


mutKey_o = selfMutateKey(mutKey_o, 3, state,1); for (int i = 0; i < 95; i++) map[i] = 0; //nulstil arr  for (int i = 1; i < 96; i++)
{ if (retning == 1) retning = 0; else retning = 1; //håndter key  if (keyStep > mutKey_o.Length - 1) keyStep = 0;


keyChar = (byte)mutKey_o[keyStep];
refIndex = i + (int)keyChar; if (refIndex > 95)
{ if (refIndex - 95 <= 95) refIndex = refIndex - 95; else {
floatValue = refIndex / 95.0;
intPart = (int)floatValue;
fraPart = floatValue - intPart; if (fraPart == 0.0) fraPart = 1.0;
refIndex = Convert.ToInt32(95 * fraPart);
}
}


refIndex--; //pga arr 0- 94  if (map[refIndex] == 0) map[refIndex] = i; else {
emptyFound = false; do { if (retning == 1)
{
refIndex++; if (refIndex > 94) refIndex = 0; if (map[refIndex] == 0)
{
map[refIndex] = i;
emptyFound = true;
}
} else {
refIndex--; if (refIndex < 0) refIndex = 94; if (map[refIndex] == 0)
{
map[refIndex] = i;
emptyFound = true;
}
}


} while (emptyFound == false);
}


keyStep++;
} for (int i = 0; i < 95; i++)
{ for (int k = 0; k < 95; k++)
{ if (map[k] == i + 1)
{
mapRev[i] = (k + 1); break;
}
}

} private void genSeedC(string key, int lenKey, long tekstLen)
{
seedC = seedC + (byte)Convert.ToChar(key[keyIndexC]);
keyIndexC++; if (keyIndexC > lenKey - 1)
{
keyIndexC = 0;
mutKey_i = selfMutateKey(key,2,1,2);
}
} private void genSeedK(string key, int lenKey, long tekstLen)
{
seedK = seedK + (byte)Convert.ToChar(key[keyIndexK]);
keyIndexK++; if (keyIndexK > lenKey - 1) keyIndexK = 0;
} private string encrypt_decrypt(string tekst, int state, int keyLen, long tekstLen, string mode)
{ Byte changedByte; string encryptTekst = ""; if (state == 1) tekst = chainChangeChars(tekst); Byte[] encodedBytes = ascii.GetBytes(tekst); foreach (Byte byteChar in encodedBytes)
{ if (state == 0) 
changedByte = changeByteRev(byteChar, keyLen, tekstLen, mode); else changedByte = changeByte(byteChar, keyLen, tekstLen, mode);
encryptTekst = encryptTekst + Convert.ToString(Convert.ToChar(changedByte));
} if (state == 0) encryptTekst = chainChangeCharsRev(encryptTekst); return encryptTekst;
} private void startProcess(int state)
{ string encryptTekst; string normalTekst; long tekstLen=0; int keyLen=0; long rounds=2; if (state == 1)
{
normalTekst = ClearTekst;
repSpecChar(ref normalTekst);
} else normalTekst = EncryptedTekst;
 
preSeed(ref tekstLen, ref normalTekst, ref keyLen, ref rounds, ref state);
prepMutKey(); if (state == 0) shuffleKeyToEndState("");


encryptTekst = normalTekst; for (int r = 1; r <= rounds; r++) //Rounds  {
shuffleArr(state);
mutKey_i = mutKey_o + "C";
keyIndexC = 0;
seedC = (int)tekstLen + 96;
encryptTekst = encrypt_decrypt(encryptTekst, state, keyLen, tekstLen, "C");
} if (state == 0) 
{
repSpecCharRev(ref encryptTekst); 
ClearTekst = encryptTekst;
} else EncryptedTekst = encryptTekst;
} private void prepMutKey()
{ int changeTegn;


mutKey_o = mutKey_i + "l2en7fg3qi8sn5go8tn2f0sw9lg4vx"; for (int i = 0; i < mutKey_o.Length; i++)
{
changeTegn = Convert.ToChar(mutKey_o[i]); if ((changeTegn < 32) || (changeTegn > 126)) mutKey_o = mutKey_o.Substring(0, i) + "?" + mutKey_o.Substring(i + 1, mutKey_o.Length - (i + 1));  
}


mutKey_o = mutKey_o.Replace("æ", "ae");
mutKey_o = mutKey_o.Replace("Æ", "AE");
mutKey_o = mutKey_o.Replace("ø", "oe");
mutKey_o = mutKey_o.Replace("Ø", "OE");
mutKey_o = mutKey_o.Replace("å", "aa");
mutKey_o = mutKey_o.Replace("Å", "AA");
} private void shuffleKeyToEndState(string normalTekst)
{ long tekstLen = 0; int keyLen = 0; long rounds = 2; int state = 1;


preSeed(ref tekstLen, ref normalTekst, ref keyLen, ref rounds, ref state); for (int r = 1; r <= rounds+1; r++) //Rounds  {
mutKey_o = selfMutateKey(mutKey_o, 3, 1,1);
}
} private string selfMutateKey(string key, long rounds, int state, int Kmode)
{ string encryptKey; string clearKey; long tekstLen = 0; int keyLen = 0; int[] map_b = new int[95]; int[] mapRev_b = new int[95]; //Krypter key på et statisk arr  int[] map_ = new int[95] { 81, 43, 90, 21, 54, 82, 94, 18, 59, 20, 80, 45, 42, 73, 7, 40, 78, 47, 28, 46, 17, 3, 75, 38, 57, 56, 52, 19, 72, 92, 10, 50, 53, 39, 84, 1, 15, 62, 14, 88, 9, 33, 79, 51, 86, 22, 48, 91, 27, 55, 67, 31, 35, 4, 65, 29, 63, 41, 16, 30, 76, 89, 83, 25, 37, 49, 66, 23, 87, 93, 32, 2, 69, 24, 61, 64, 60, 12, 6, 26, 5, 95, 85, 44, 68, 71, 70, 34, 58, 8, 36, 74, 11, 13, 77 }; int[] mapRev_ = new int[95] { 36, 72, 22, 54, 81, 79, 15, 90, 41, 31, 93, 78, 94, 39, 37, 59, 21, 8, 28, 10, 4, 46, 68, 74, 64, 80, 49, 19, 56, 60, 52, 71, 42, 88, 53, 91, 65, 24, 34, 16, 58, 13, 2, 84, 12, 20, 18, 47, 66, 32, 44, 27, 33, 5, 50, 26, 25, 89, 9, 77, 75, 38, 57, 76, 55, 67, 51, 85, 73, 87, 86, 29, 14, 92, 23, 61, 95, 17, 43, 11, 1, 6, 63, 35, 83, 45, 69, 40, 62, 3, 48, 30, 70, 7, 82, };
map_b = map;
mapRev_b = mapRev;
map = map_;
mapRev = mapRev_;


clearKey = key;
tekstLen = clearKey.Length; if (Kmode == 1)
mutKey_i = Key; else mutKey_i = mutKey_o;


keyLen = mutKey_i.Length;

encryptKey = clearKey; for (int r = 1; r <= rounds; r++)//rounds  {
keyIndexK = 0;
seedK = (int)tekstLen + 96;
encryptKey = encrypt_decrypt(encryptKey, state, keyLen, tekstLen, "K");
}


map = map_b;
mapRev = mapRev_b; return encryptKey;
} public System.Collections.IEnumerable enumRounds(int state)
{ string encryptTekst; string normalTekst; long tekstLen = 0; int keyLen = 0; long rounds = 2; if (Key.Length > 0)
{ if (((state == 1) && (ClearTekst.Length > 0)) || ((state == 0) && (EncryptedTekst.Length > 0)))
{ if (state == 1)
{
normalTekst = ClearTekst;
repSpecChar(ref normalTekst);
} else normalTekst = EncryptedTekst;


preSeed(ref tekstLen, ref normalTekst, ref keyLen, ref rounds, ref state);
prepMutKey(); if (state == 0) shuffleKeyToEndState("");


encryptTekst = normalTekst; for (int r = 1; r <= rounds; r++)
{
shuffleArr(state);
mutKey_i = mutKey_o + "C";
keyIndexC = 0;
seedC = (int)tekstLen + 96;
encryptTekst = encrypt_decrypt(encryptTekst, state, keyLen, tekstLen, "C"); yield return encryptTekst;
} if (state == 0)
{
repSpecCharRev(ref encryptTekst);
ClearTekst = encryptTekst; yield return encryptTekst;
} else EncryptedTekst = encryptTekst;
}
} else errorState = -2;
} private void preSeed(ref long tekstLen, ref string normalTekst, ref int keyLen, ref long rounds, ref int state)
{            
tekstLen = normalTekst.Length;
mutKey_i = Key; // mutKey_i born  keyLen = mutKey_i.Length;
rounds = keyLen + 20; if (Fastmode) rounds = 2;
} private void repSpecChar(ref string normalTekst)
{ int ranN; char ranChar; int changeTegn;


normalTekst = normalTekst.Replace("æ", "e6kw7x1140z92vc485w2@1@");
normalTekst = normalTekst.Replace("Æ", "e6kw7x1140z92vc485w2@2@");
normalTekst = normalTekst.Replace("ø", "e6kw7x1140z92vc485w2@3@");
normalTekst = normalTekst.Replace("Ø", "e6kw7x1140z92vc485w2@4@");
normalTekst = normalTekst.Replace("å", "e6kw7x1140z92vc485w2@5@");
normalTekst = normalTekst.Replace("Å", "e6kw7x1140z92vc485w2@6@");
normalTekst = normalTekst.Replace("á", "e6kw7x1140z92vc485w2@7@");
normalTekst = normalTekst.Replace("Á", "e6kw7x1140z92vc485w2@8@");
normalTekst = normalTekst.Replace("à", "e6kw7x1140z92vc485w2@9@");
normalTekst = normalTekst.Replace("À", "e6kw7x1140z92vc485w2@10@");
normalTekst = normalTekst.Replace("é", "e6kw7x1140z92vc485w2@11@");
normalTekst = normalTekst.Replace("É", "e6kw7x1140z92vc485w2@12@");
normalTekst = normalTekst.Replace("è", "e6kw7x1140z92vc485w2@13@");
normalTekst = normalTekst.Replace("È", "e6kw7x1140z92vc485w2@14@");
normalTekst = normalTekst.Replace("ó", "e6kw7x1140z92vc485w2@15@");
normalTekst = normalTekst.Replace("Ó", "e6kw7x1140z92vc485w2@16@");
normalTekst = normalTekst.Replace("ò", "e6kw7x1140z92vc485w2@17@");
normalTekst = normalTekst.Replace("Ò", "e6kw7x1140z92vc485w2@18@");
normalTekst = normalTekst.Replace("ś", "e6kw7x1140z92vc485w2@19@");
normalTekst = normalTekst.Replace("Ś", "e6kw7x1140z92vc485w2@20@");
normalTekst = normalTekst.Replace("ú", "e6kw7x1140z92vc485w2@22@");
normalTekst = normalTekst.Replace("Ú", "e6kw7x1140z92vc485w2@23@");
normalTekst = normalTekst.Replace("ù", "e6kw7x1140z92vc485w2@24@");
normalTekst = normalTekst.Replace("Ù", "e6kw7x1140z92vc485w2@25@");
normalTekst = normalTekst.Replace("í", "e6kw7x1140z92vc485w2@26@");
normalTekst = normalTekst.Replace("Í", "e6kw7x1140z92vc485w2@27@");
normalTekst = normalTekst.Replace("ì", "e6kw7x1140z92vc485w2@28@");
normalTekst = normalTekst.Replace("Ì", "e6kw7x1140z92vc485w2@29@");
normalTekst = normalTekst.Replace("ź", "e6kw7x1140z92vc485w2@30@");
normalTekst = normalTekst.Replace("Ź", "e6kw7x1140z92vc485w2@31@");
normalTekst = normalTekst.Replace("ć", "e6kw7x1140z92vc485w2@32@");
normalTekst = normalTekst.Replace("Ć", "e6kw7x1140z92vc485w2@33@");
normalTekst = normalTekst.Replace("\r", "e6kw7x1140z92vc485w2@34@");
normalTekst = normalTekst.Replace("\n", "e6kw7x1140z92vc485w2@35@");
normalTekst = normalTekst.Replace("’", "e6kw7x1140z92vc485w2@36@");
normalTekst = normalTekst.Replace("\t", "e6kw7x1140z92vc485w2@37@");
normalTekst = normalTekst.Replace("“", "e6kw7x1140z92vc485w2@38@");
normalTekst = normalTekst.Replace("”", "e6kw7x1140z92vc485w2@39@"); for (int i = 0; i < normalTekst.Length; i++)
{
changeTegn = Convert.ToChar(normalTekst[i]); if ((changeTegn < 32) || (changeTegn > 126))
{
normalTekst = normalTekst.Substring(0, i) + "?" + normalTekst.Substring(i + 1, normalTekst.Length - (i + 1));
errorState = -1;
}
} if (Randomization)
{
Random rnd = new Random();
ranN = rnd.Next(32, 127);
ranChar = (char)((byte)ranN);
normalTekst = ranChar + normalTekst;
} else normalTekst = normalTekst[0] + normalTekst;
} private void repSpecCharRev(ref string normalTekst)
{
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@1@","æ");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@2@","Æ");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@3@","ø");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@4@","Ø");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@5@","å");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@6@","Å");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@7@","á");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@8@","Á");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@9@","à");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@10@","À");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@11@","é");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@12@","É");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@13@","è");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@14@","È");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@15@","ó");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@16@","Ó");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@17@","ò");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@18@","Ò");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@19@","ś");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@20@","Ś");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@22@","ú");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@23@","Ú");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@24@","ù");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@25@","Ù");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@26@","í");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@27@","Í");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@28@","ì");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@29@","Ì");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@30@","ź");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@31@","Ź");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@32@","ć");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@33@","Ć");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@34@","\r"); 
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@35@","\n");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@36@", "’");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@37@", "\t");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@38@", "“");
normalTekst = normalTekst.Replace("e6kw7x1140z92vc485w2@39@", "”");


normalTekst = normalTekst.Substring(1, normalTekst.Length - 1);
} public void Encrypt()
{ if (Key.Length > 0) { if (ClearTekst.Length > 0) startProcess(1);
} else errorState = -2;
} public void Decrypt()
{ if (Key.Length > 0) { if (EncryptedTekst.Length > 0) startProcess(0);
} else errorState = -2;
}
}
 




<h< div="">
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
M2encryption49.04 kB2015-02-26 22:21
...

Comments

(Add your comment, get 0.1 Point)
Minimum:15 words, Maximum:160 words
名字很难起
2015-04-20

希望能够借鉴楼主的算法,非常感谢楼主提供的资料

  • 1
  • Page 1
  • Total 1

M2 a proprietary encryption algorithm (5.14 kB)

Need 1 Point(s)
Your Point (s)

Your Point isn't enough.

Get 22 Point immediately by PayPal

Point will be added to your account automatically after the transaction.

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more Points

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D