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
OTP4U (One Time Pad For You) - KM_Permutation.java

KM_Permutation.java

Caricato da: Teutoburgo
Scarica il programma completo

  1. /*
  2.     OTP4U 0.8.0 - One Time Pad for you
  3.     Copyright (C) 2003 Pierre Blanc
  4.     Pierre Blanc: blanc_teutoburgo@yahoo.it
  5.     http://www.teutoburgo.tk
  6.     http://it.geocities.com/teutoburgo
  7.  
  8.     This program is free software; you can redistribute it and/or modify
  9.     it under the terms of the GNU General Public License as published by
  10.     the Free Software Foundation; either version 2 of the License, or
  11.     (at your option) any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  21.     or go to      http://www.gnu.org/copyleft/gpl.html
  22. */
  23.  
  24. package tk.teutoburgo.otp4u.crypt;
  25.  
  26. import java.util.*;
  27. import java.io.*;
  28.  
  29. /**
  30.  * Title:        OTP4U
  31.  * Description:
  32.  * Copyright:    Copyright (c) 2002
  33.  * Company:      Teutoburgo
  34.  * @author Pierre Blanc
  35.  * @version 1.0
  36.  */
  37.  
  38. public class KM_Permutation extends KeyManager{
  39.  
  40.   KeyPermutator kp = new KeyPermutator();
  41.  
  42.   public KM_Permutation() {
  43.   }
  44.   public KM_Permutation(String home, Boolean isGui) {
  45.       super(home, isGui);
  46.   }
  47.  
  48.   public void writePublicKey() throws IOException, FileNotFoundException{
  49.         byte[][] entropyFiles = io.readRandomKey(OTP4U_HOME + ENTROPY);
  50.         byte[] publicKeyBytes = this.compactEntropyFiles(entropyFiles);
  51.         byte[] oldKey4Key = io.readFile(OTP4U_HOME + RANDOM_KEY +KEY4KEY +
  52.                                         KEY4KEY_FILE);
  53.         io.writeFile(OTP4U_HOME+ PUBLIC_KEY + PUBLIC_KEY_FILE ,
  54.                      publicKeyBytes);
  55.         writeKeys(publicKeyBytes, oldKey4Key);
  56.   }
  57.   public void writeRandomKey() throws IOException, FileNotFoundException{
  58.         byte[] publicKeyBytes = io.readFile(OTP4U_HOME+
  59.           PUBLIC_KEY + PUBLIC_KEY_FILE), oldKey4Key = io.readFile(
  60.           OTP4U_HOME + RANDOM_KEY +KEY4KEY + KEY4KEY_FILE);
  61.         writeKeys(publicKeyBytes, oldKey4Key);
  62.   }
  63.  
  64.   public void writeKeys(byte[] publicKeyBytes, byte[] k4k)throws IOException,
  65.                 FileNotFoundException{
  66.         mp.sPrintLog("Getting keys .....");
  67.         byte[][] iterated = kp.recurrence(publicKeyBytes, k4k);
  68.         io.writeFile(OTP4U_HOME + RANDOM_KEY + RANDOM_KEY_FILE,
  69.                      iterated[0]);
  70.         io.writeFile(OTP4U_HOME +RANDOM_KEY+ KEY4KEY +
  71.                      KEY4KEY_FILE , iterated[1]);
  72.   }
  73. }