Commit 12802310 authored by Elia Carrara's avatar Elia Carrara
Browse files

adjusted comments and changed prime size to 1024

parent 54de16ab
......@@ -5,13 +5,13 @@ import java.math.BigInteger;
public class FileEncryptor {
/**
*
* Decrypts a file.
* @param keyFile
* file with cryption key-values stored
* file path with private key
* @param inputFile
* file to be decrypted
* @param outputFile
* decyrpted content
* Here the decrypted output will be generated
*/
public static void decryptFile(String keyFile, String inputFile, String outputFile) {
......@@ -36,13 +36,13 @@ public class FileEncryptor {
}
/**
*
* Encrypts a file.
* @param keyFile
* file with cryption key-values stored
* file with public key
* @param inputFile
* file to be encrypted
* @param outputFile
* encrypted content
* Here the encrypted output will be generated
*/
public static void encryptFile(String keyFile, String inputFile, String outputFile) {
......
......@@ -9,13 +9,13 @@ import java.math.BigInteger;
public class FileHandler {
/**
*
* Creates a serialized string of a key pair
* @param n
* the first number of the public or private key (n)
* @param key
* secret or private key
* public or private key
* @return
* StringBuilder in the form of: '(n,key)'
* String in the form of: '(n,key)'
*/
public static String serializeKeyPair(BigInteger n, BigInteger key) {
......@@ -29,11 +29,12 @@ public class FileHandler {
}
/**
*
* Deserializes a key file content.
* @param filecontent
* Key-Value to be de-serialized
* @return
* Array consisting of n and the key
* Array[0] = n (modulus)
* Array[1] = private or public key
*/
public static BigInteger[] deserializeKeyPair(String filecontent) {
......@@ -46,9 +47,9 @@ public class FileHandler {
}
/**
*
* Serializes an array of bigintegers to a string.
* @param numbers
* Array of content to be serialized
* Array of bigintegers to be serialized
* @return
* a String that separates every number with a comma ','
*/
......@@ -68,11 +69,11 @@ public class FileHandler {
}
/**
*
* Deserializes the string of bigintegers to a biginterger array
* @param content
* Content to be de-serialized
* @return
* Array consisting of a number
* Array consisting of bigintegers
*/
public static BigInteger[] deserializeEncryptedContent(String content) {
......@@ -88,9 +89,9 @@ public class FileHandler {
/**
*
* Writes a string to a file.
* @param path
* the directory of the file
* the file path
* @param content
* the serialized content
* @return
......@@ -121,9 +122,9 @@ public class FileHandler {
}
/**
*
* Reads a string from a file
* @param path
* directory of the file, that should be read
* Path of the file, that should be read
* @return
* the content of the file
*/
......@@ -155,7 +156,7 @@ public class FileHandler {
}
/**
*
* Checks if directory exists.
* @param dirPath
* directory to be checked
* @return
......@@ -168,7 +169,7 @@ public class FileHandler {
}
/**
*
* Checks if file exists.
* @param filePath
* directory to file to be checked
* @return
......
......@@ -4,20 +4,28 @@ import java.math.BigInteger;
import java.util.Random;
public class RSAHandler {
static final int PRIME_BIT_LENGTH = 128;
static final int PRIME_BIT_LENGTH = 1024;
/**
* Returns phi of (p*q)=n
* @param p first prime of the prime factorisation of n
* @param q second prime of the prime factorisation of n
* @return returns the size of the set Z* (phi of n)
*/
public static BigInteger eulersTotientFunction(BigInteger p, BigInteger q) {
return p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE)); // (p-1) * (q-1)
}
/**
*
* This is an implementation of the extended euclidean algorithm.
* This is primarily used to compute the gcd of a and b.
* @param a
* public modulus n
* First number
* @param b
* public key
* Second number
* @return
* Array with p and q for the private key
* Array[0] = gcd of a and b
* gcd(a,b) = Array[1]*a + Array[2]*b
*/
public static BigInteger[] extendedEuclideanAlgorithm(BigInteger a, BigInteger b) {
BigInteger[] out = new BigInteger[3];
......@@ -57,9 +65,9 @@ public class RSAHandler {
}
/**
*
* Creats a prime with the the bit length PRIME_BIT_LENGTH
* @return
* a random BigInteger
* a random BigInteger prime
*/
public static BigInteger createPrime() {
......@@ -68,7 +76,7 @@ public class RSAHandler {
/**
*
* Here the magic of creating a rsa key pair happens.
* @param directory
* directory to store the sk.txt and pk.txt
* @return
......@@ -111,12 +119,13 @@ public class RSAHandler {
}
/**
* Here the en-/decryption takes place. (x^exp mod n)
* @param x
* the Number on which the action is perfomed on
* the message number
* @param n
* the first number of the public or private key (n)
* the modulus
* @param exp
* the second number of the public or private key (e or d)
* the exponent
*
* @return x ^ exp mod n
*/
......
......@@ -17,7 +17,7 @@ public class RSAHandlerTest {
expected[1] = new BigInteger("8");
expected[2] = new BigInteger("-13");
BigInteger[] result = RSAHandler.extendedEucleadeanAlgorithm(a, b);
BigInteger[] result = RSAHandler.extendedEuclideanAlgorithm(a, b);
assertArrayEquals(expected, result);
}
......@@ -31,7 +31,7 @@ public class RSAHandlerTest {
expected[1] = new BigInteger("40147");
expected[2] = new BigInteger("-86215");
BigInteger[] result = RSAHandler.extendedEucleadeanAlgorithm(a, b);
BigInteger[] result = RSAHandler.extendedEuclideanAlgorithm(a, b);
assertArrayEquals(expected, result);
}
......@@ -45,7 +45,7 @@ public class RSAHandlerTest {
expected[1] = new BigInteger("193");
expected[2] = new BigInteger("-5506");
BigInteger[] result = RSAHandler.extendedEucleadeanAlgorithm(a, b);
BigInteger[] result = RSAHandler.extendedEuclideanAlgorithm(a, b);
assertArrayEquals(expected, result);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment