Java plaintext cipher Triple encryption method _java

Source: Internet
Author: User
Tags comparison table

This article introduces two methods of cipher encryption, these two are very common can be found at random Baidu.

1. Morse Code;

Say password encryption has to be put to the method. It's a classic.

First of all, tell him the comparison table, directly above the picture.

The core idea is to replace the plaintext cipher and replace the characters with the. two symbols;

2, fence password;

The so-called fence password, is to encrypt the clear text into a group of N, and then the 1th word of each group together, forming a period of irregular words. But the fence code itself has a unspoken rule that the letters that make up the fence are not usually too many. (generally not more than 30, that is, one or two words)

There's nothing to say about it. A chestnut: Encrypt the plaintext asdfghjkl, and divide it into two groups: the base position and the even digit. Then the two groups merged into ADGJLSFHK;

I have a combination of these two encryption methods to a plaintext password triple encryption: The first layer of the fence once, the second layer of fences once again, the third layer of Morse encryption;
First the fence section:

 * * Fence decryption class/public class Fence {/* Encryption part/public string encryption (string password)
    {String p = new string ();
    string P1 = new string ();
    string P2 = new string ();
      for (int i = 0; i < password.length (); i++) {if (i%2 = = 0) P1 + = p.valueof (Password.charat (i)); 
    else P2 + = p.valueof (Password.charat (i));
  return P1+P2;
    /* Decryption Part */public string decode (string fencepassword) {String password = new string ();
    String p = new string ();
    String p1 = fencepassword.substring (0, Fencepassword.length ()/2);
    String P2 = fencepassword.substring (Fencepassword.length ()/2);
    int i;
    for (i = 0; i < p1.length (); i++) {password + = p.valueof (P1.charat (i)) + p.valueof (P2.charat (i));
    } if (Fencepassword.length ()%2!= 0) Password + = p.valueof (P2.charat (i));
  return password; }
}

Then the Morse section :
This part is more cumbersome, the Morse code and symbol in the match between the problem, want to use an array to store, and then loop to match; but I am a not afraid of trouble to simply a person, on a one-after comparison;
  then made a two-time encryption and decryption of the fence when Morse encryption was decrypted; This can be used when encrypting and decrypting as long as the encryption and decryption function of Morse class is invoked.

* Morse encryption and Decryption class * * Import Java.util.StringTokenizer;
  public class Morse {* * Morse password and character matching constant * * Final String A = ".-";
  Final String B = "---.";
  Final String C = "-.-.";
  Final String D = "-..";
  Final String E = "."; Final String F = "..
  -.";
  Final String G = "--.";
  Final String H = "...";
  Final String I = "..";
  Final String J = ".---";
  Final String K = "-.-";
  Final String L = ".-..";
  Final String M = "--";
  Final String N = "-.";
  Final String O = "---";
  Final String P = ".--.";
  Final String Q = "--.-";
  Final String R = ".-.";
  Final String S = "...";
  Final String T = "-"; Final String U = "..
  -";
  Final String V = "...-";
  Final String W = ".--"; Final String X = "-..
  -";
  Final String Y = "-.--";
  Final String Z = "--..";
  Final String $ = "-----";
  Final String $ = ".----"; Final String $ = "..
  ---";
  Final String $ = "...-";
  Final String $ = "...-";
  Final String $ = "...";
  Final String $ = "-...."; Final String $ = "--...";
  Final String $ = "---..";
  Final String $ = "----."; Final String period = ".-.-.-";
  // . Final String colon = "---..."; : final String comma = "--.. --"; , final String semicolon = "-.-.-.";
  // ; Final String question = ".. --..";
  // ? Final String equal = "-...-"; = Final String doublequotation = ".-.. -.";/ /"Final String singlequotation =".----. "; /' final String slash = '-.. -."; Final String exclamation = "-.-.--";
  // ! Final String hyphen = "-....-"; -Final String underscore = ".. --.-"; _ Final String lroundbrackets = "-.--."; (Final string rroundbrackets = "-.--.-";//) Final string $ = "...-.. -"; $ final String ampersand = ".-..."; & Final String at = ".--.-."; @ final String plus = ".-.-.";
    +//* encryption corresponding match */public String Matching (string str) {switch (str) {case "a": return A;
    Case "B": return B;
    Case "C": return C;
    Case "D": return D; Case "E":
      return E;
    Case "F": return F;
    Case "G": return G;
    Case "H": return h;
    Case "I": return i;
    Case "J": Return J;
    Case "K": return K;
    Case "L": return L;
    Case "M": return m;
    Case "n": return n;
    Case "O": return o;
    Case "P": return p;
    Case "Q": Return q;
    Case "R": Return r;
    Case "S": return S;
    Case "T": return t;
    Case "U": return u;
    Case "V": return v;
    Case "W": Return w;
    Case "X": Return x;
    Case "Y": return y;
    Case "Z": Return z;
    Case "0": return $;
    Case "1": return $;
    Case "2": return $;
    Case "3": return $;
    Case "4": return $ $;
    Case "5": return $;
    Case "6": return $;
    Case "7": return $;
    Case "8": return $;
    Case "9": return $;
    Case ".": Return period; Case ":": return colon;
    Case ",": return comma;
    Case ";": return semicolon;
    Case "?": return question;
    Case "=": return equal;
    Case "\" ": Return doublequotation;
    Case "\": Return singlequotation;
    Case "/": return slash;
    Case "!": return exclamation;
    Case "-": return hyphen;
    Case "_": return underscore;
    Case "(): Return lroundbrackets;
    Case "]": return rroundbrackets;
    Case "$": return $;
    Case "&": return ampersand;
    Case "@": return at;
    Case "+": return plus;
  Return "";
    /* Morse Encryption */public string encryption (string password) {Fence f = new Fence ();
    Password = f.encryption (password);
    Password = f.encryption (password);
    String morsepasswork = new string ();
    String MP = new string ();
      for (int i = 0; i < password.length (); i++) {MP = mp.valueof (Password.charat (i)); Morsepasswork + = Matching (MP) + "/";
  return morsepasswork;
    }/* Decrypt the match for the exchange */public String matching2 (String str) {if (Str.equals (A)) return "A";
    else if (Str.equals (b)) return "B";
    else if (Str.equals (c)) return "C";
    else if (Str.equals (d)) return "D";
    else if (Str.equals (e)) return "E";
    else if (Str.equals (f)) return "F";
    else if (str.equals (g)) return "G";
    else if (str.equals (h)) return "H";
    else if (str.equals (i)) return "I";
    else if (Str.equals (j)) return "J";
    else if (Str.equals (k)) return "K";
    else if (Str.equals (L)) return "L";
    else if (Str.equals (m)) return "M";
    else if (str.equals (n)) return "n";
    else if (str.equals (O)) return "O";
    else if (Str.equals (p)) return "P";
    else if (str.equals (q)) return "Q";
    else if (Str.equals (R)) return "R";
    else if (str.equals (s)) return "S"; else if (Str.equals (t)) return "T";
    else if (str.equals (U)) return "U";
    else if (Str.equals (v)) return "V";
    else if (Str.equals (w)) return "W";
    else if (str.equals (x)) return "X";
    else if (str.equals (y)) return "Y";
    else if (Str.equals (z)) return "Z";
    else if (str.equals ($)) return "0";
    else if (str.equals ($)) return "1";
    else if (str.equals ($)) return "2";
    else if (str.equals ($)) return "3";
    else if (str.equals ($)) return "4";
    else if (str.equals ($)) return "5";
    else if (str.equals ($)) return "6";
    else if (str.equals ($)) return "7";
    else if (str.equals ()) return "8";
    else if (str.equals ($)) return "9";
    else if (str.equals (period)) return ".";
    else if (str.equals (colon)) return ":";
    else if (str.equals (comma)) return ",";
    else if (str.equals (semicolon)) return ";"; else if (str. Equals (question)) return "?";
    else if (str.equals (equal)) return "=";
    else if (str.equals (doublequotation)) return "\";
    else if (str.equals (singlequotation)) return "\";
    else if (Str.equals (slash)) return "/";
    else if (str.equals (exclamation)) return "!";
    else if (str.equals (hyphen)) return "-";
    else if (str.equals (underscore)) return "_";
    else if (str.equals (lroundbrackets)) return "(";
    else if (str.equals (rroundbrackets)) return ";
    else if (str.equals ($)) return "$";
    else if (str.equals (ampersand)) return "&";
    else if (str.equals ()) return "@";
    else if (str.equals (plus)) return "+";
  else return "";
    /* Morse decryption */public string decode (string morsepassword) {String password = new string ();
    Fence f = new Fence ();
    StringTokenizer p = new StringTokenizer (Morsepassword, "/"); while (P.hasmoreelements ()) {PassWord + = Matching2 (P.nexttoken ());
    } password = f.decode (password);
    Password = f.decode (password);
  return password;
 }
}

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.