Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Sysepub - Syxor.java

Syxor.java

Caricato da: Teutoburgo
Scarica il programma completo

  1. /*
  2.     Sysepub 0.8 - A Symmetric Semi-Public key cipher
  3.     Copyright (C) 2002 Pierre Blanc
  4.     Pierre Blanc: blanc_teutoburgo@yahoo.it
  5.     http://it.geocities.com/teutoburgo
  6.  
  7.     This program is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation; either version 2 of the License, or
  10.     (at your option) any later version.
  11.  
  12.     This program is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.     GNU General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  20.     or go to      http://www.gnu.org/copyleft/gpl.html
  21. */
  22. import java.io.IOException;
  23. /**
  24.  * Class Syxor - The XOR used by Sysepub
  25.  * Creation date: (30/08/2002 13.12.05)
  26.  * @author: Pierre Blanc
  27.  */
  28. public class Syxor {
  29. /**
  30.  * Syxor constructor comment.
  31.  */
  32. public Syxor() {
  33.         super();
  34. }
  35.     public byte[] decrypt(byte[] encrypted, byte[] key) {
  36.                 int i=0;
  37.         int length= encrypted.length;
  38.         int keyLength=key.length;
  39.         byte[] message = new byte[length];
  40.  
  41.         for (i = 0; i < length && i<keyLength ; i++) {
  42.           message[i]=(byte)(encrypted[i]^key[i]);
  43.         }
  44.  
  45.         return message;
  46.     }
  47. public byte[] encrypt(byte[] message, byte[] key) {
  48.     int length=message.length;
  49.     byte[] encrypted = new byte[length];
  50.  
  51.     for (int i = 0; i < length && i<key.length; i++) {
  52.       encrypted[i]=(byte)(message[i]^key[i]);
  53.     }
  54.     return encrypted;
  55. }
  56. public static void main(String args[]){
  57. /*  Syxor s= new Syxor();
  58.   byte[] x = new byte[10];
  59.   byte[] mng = new byte[10];
  60.   for (int i = 0; i < 10; i++) {
  61.       x[i] = (byte) (i + 70);
  62.       mng[i] = (byte) (i + 80);
  63.   }
  64.   byte [] test=s.encrypt(x, mng);
  65.   byte [] testd=s.decrypt(test, mng);
  66.   try{
  67.     System.out.write(x);
  68.     System.out.println();
  69.     System.out.write(mng);
  70.     System.out.println("result");
  71.     System.out.write(test);
  72.     System.out.println("result2");
  73.     System.out.write(testd);
  74.  
  75.   } catch (IOException ioe){
  76.     ioe.printStackTrace();
  77.   }
  78. */
  79. }
  80. }