A secret encryption and decryption algorithm

Source: Internet
Author: User

static int max=100;static char[] key=new char[max];//for saving key static int len;static char[] Bitcode (char[] str)//One-time encryption algorithm {    int i;    Char[] Wen;        if ((wen=new char[len+1]) ==null) {System.out.printf ("Request memory failed!\n");    System.exit (1);    } for (i=0;i<len;i++) {wen[i]= (char) (str[i]^key[i]);//XOR operation} wen[len]= ' + '; Return wen;}    public static void Main (string[] args) throws IOException {int i;char[] srcstr=new Char[max]; Char[] Miwen,mingwen; String go; Scanner input=new Scanner (system.in);//srand (Time (NULL));//random seed System.out.printf ("Once a secret encryption decryption algorithm demo! \ n ");d o{system.out.printf (" Please enter a clear text string: ");        BufferedReader BufferedReader = new BufferedReader (new InputStreamReader (system.in));          String Str=bufferedreader.readline ();         Srcstr=str.tochararray ();//plaintext Information random r=new random (); Random seed len=srcstr.length;for (i=0;i<len;i++) {key[i]= (char) (R.nextint (10) + ' 0 ');//Generate Key sequence}system.out.printf (" The key sequence for this encryption and decryption demo is: "); for (i=0;i<len;i++) {System.out.printf ("%c ", key[i]);}    System.out.printf ("\ n");    Miwen=bitcode (SRCSTR);//encryption System.out.printf ("\ n input plaintext:");    for (i=0;i<srcstr.length;i++) System.out.print (Srcstr[i]);    System.out.printf ("\ n encrypted cipher:");    for (i=0;i<miwen.length;i++) System.out.print (Miwen[i]);    Mingwen=bitcode (Miwen);//Decrypt System.out.printf ("\ n decrypt the plaintext as:");        for (i=0;i<mingwen.length;i++) System.out.print (Mingwen[i]);    System.out.print ("\ n \ nthe continuation (y/n)?"); Go=input.next ();} while (Go.equalsignorecase ("Y")); System.out.println ("The demo is over!" ");}

A secret encryption and decryption algorithm

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.