inital commit
This commit is contained in:
commit
2f8c04134f
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
1
.idea/description.html
generated
Normal file
1
.idea/description.html
generated
Normal file
@ -0,0 +1 @@
|
|||||||
|
<html>Simple <b>Java</b> application that includes a class with <code>main()</code> method</html>
|
6
.idea/encodings.xml
generated
Normal file
6
.idea/encodings.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="PROJECT" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
12
.idea/misc.xml
generated
Normal file
12
.idea/misc.xml
generated
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="EntryPointsManager">
|
||||||
|
<entry_points version="2.0" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectKey">
|
||||||
|
<option name="state" value="project://e2804f05-5315-4fc6-a121-c522a6c26470" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_14" default="true" project-jdk-name="14" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/out" />
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/ModularArithmaticCalculator.iml" filepath="$PROJECT_DIR$/ModularArithmaticCalculator.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
3
.idea/project-template.xml
generated
Normal file
3
.idea/project-template.xml
generated
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<template>
|
||||||
|
<input-field default="com.company">IJ_BASE_PACKAGE</input-field>
|
||||||
|
</template>
|
12
ModularArithmaticCalculator.iml
Normal file
12
ModularArithmaticCalculator.iml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||||
|
<exclude-output />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
|
|
Binary file not shown.
BIN
out/production/ModularArithmaticCalculator/util/Dump.class
Normal file
BIN
out/production/ModularArithmaticCalculator/util/Dump.class
Normal file
Binary file not shown.
Binary file not shown.
146
src/tech/loedige/Main.java
Normal file
146
src/tech/loedige/Main.java
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
package tech.loedige;
|
||||||
|
|
||||||
|
import util.Dump;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Main {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// write your code here
|
||||||
|
int Z = 13;
|
||||||
|
/*getOrderAndInverse(Z);
|
||||||
|
|
||||||
|
getPrimitiveElement(2);
|
||||||
|
getPrimitiveElement(3);
|
||||||
|
getPrimitiveElement(5);
|
||||||
|
getPrimitiveElement(7);
|
||||||
|
getPrimitiveElement(11);
|
||||||
|
getPrimitiveElement(13);
|
||||||
|
getPrimitiveElement(17);
|
||||||
|
getPrimitiveElement(19);
|
||||||
|
getPrimitiveElement(23);*/
|
||||||
|
|
||||||
|
|
||||||
|
/*getGroupAndMaxOrder(4);
|
||||||
|
getGroupAndMaxOrder(6);
|
||||||
|
getGroupAndMaxOrder(8);
|
||||||
|
getGroupAndMaxOrder(9);
|
||||||
|
getGroupAndMaxOrder(10);
|
||||||
|
getGroupAndMaxOrder(12);
|
||||||
|
getGroupAndMaxOrder(14);
|
||||||
|
getGroupAndMaxOrder(15);
|
||||||
|
getGroupAndMaxOrder(16);*/
|
||||||
|
|
||||||
|
/*getOrderRFC7919(2);
|
||||||
|
getOrderRFC7919(3);
|
||||||
|
getOrderRFC7919(4);
|
||||||
|
getOrderRFC7919(5);
|
||||||
|
getOrderRFC7919(6);*/
|
||||||
|
getOrderRFC7919(7);
|
||||||
|
/*getOrderRFC7919(8);
|
||||||
|
getOrderRFC7919(9);*/
|
||||||
|
|
||||||
|
getSharedSecret();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void getSharedSecret(){
|
||||||
|
BigInteger kA_pub = new BigInteger("27282667746838411939143241666723046694527264637007559423952796008903977634324023737753124358327044498235695067321378479835998035654034644517179759788901352737738466214712414616949468433629993070414307680308271213886171008791853033810348102610871852298273695732098461918442112517731219977692798111421155148916640251520848785936004364583451306844563558619725135844767334446174867008412854680440175554752338253195095533723949367607823291954964390988919344648377988215096163955782620638461956467357105200224013185118543681273714672276506212170327933806962609375007526608015272079508124813944474288170004694821130997859203");
|
||||||
|
BigInteger kB_priv = new BigInteger("7532919400457445663303700830973523590423263864724159934023391416574147324621933536449637606282131103918883626115855343351325277070984876733129265301205702642333354707816589145340968726389894044688024166108036474255111533732948913177796353881817402947686860467714661832933242570411627309386297780537824324832627012380856381669126724451049618946281819268817314740486708353781450544470119941814532875098325894703744849701616223792195949010930775348252418316672068234315909190760678573146228014902673906821408531294133290046052716296787531205413964871695349574817105255572494804346109933903949904551005148642787422867446");
|
||||||
|
BigInteger n = new BigInteger("32317006071311007300153513477825163362488057133489075174588434139269806834136210002792056362640164685458556357935330816928829023080573472625273554742461245741026202527916572972862706300325263428213145766931414223654220941111348629991657478268034230553086349050635557712219187890332729569696129743856241741236237225197346402691855797767976823014625397933058015226858730761197532436467475855460715043896844940366130497697812854295958659597567051283852132784468522925504568272879113720098931873959143374175837826000278034973198552060607533234122603254684088120031105907484281003994966956119696956248629032338072839127039");
|
||||||
|
BigInteger g = BigInteger.TWO;
|
||||||
|
|
||||||
|
BigInteger kA_B = kA_pub.modPow(kB_priv,n);
|
||||||
|
System.out.println("k_A,B= "+kA_B.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void getOrderRFC7919(int i){
|
||||||
|
BigInteger p = new BigInteger("323170060713110073001535134778251633624880571334890751745884341392698068341" +
|
||||||
|
"362100027920563626401646854585563579353308169288290230805734726252735547424612457410262025279165729728" +
|
||||||
|
"627063003252634282131457669314142236542209411113486299916574782680342305530863490506355577122191878903" +
|
||||||
|
"327295696961297438562417412362372251973464026918557977679768230146253979330580152268587307611975324364" +
|
||||||
|
"674758554607150438968449403661304976978128542959586595975670512838521327844685229255045682728791137200" +
|
||||||
|
"989318739591433741758378260002780349731985520606075332341226032546840881200311059074842810039949669561" +
|
||||||
|
"19696956248629032338072839127039");
|
||||||
|
BigInteger bi = BigInteger.valueOf(i);
|
||||||
|
BigInteger o =p.divide(bi);
|
||||||
|
o= o.add(BigInteger.ONE);
|
||||||
|
BigInteger r = bi.multiply(o);
|
||||||
|
if(r.mod(p).compareTo(BigInteger.ONE)==0){
|
||||||
|
System.out.println(i + ":\t" +o.subtract(BigInteger.ONE).toString());
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
int c = 2;
|
||||||
|
while(true){
|
||||||
|
bi = BigInteger.valueOf(i);
|
||||||
|
o =p.divide(bi);
|
||||||
|
o =o.multiply(BigInteger.valueOf(c));
|
||||||
|
o= o.add(BigInteger.ONE);
|
||||||
|
System.out.println(c);
|
||||||
|
if(r.mod(p).compareTo(BigInteger.ONE)==0){
|
||||||
|
System.out.println(i + ":\t" +o.subtract(BigInteger.ONE).toString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
c++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void getGroupAndMaxOrder(int Z){
|
||||||
|
int max = 0;
|
||||||
|
int groupOrder=0;
|
||||||
|
for(int i=1; i<Z;i++){
|
||||||
|
if(inv(Z,i)!=0){
|
||||||
|
groupOrder ++;
|
||||||
|
if(max<o(Z,i))max=o(Z,i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println(Z + ":\t" + groupOrder + "\t" + max);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void getPrimitiveElement(int Z){
|
||||||
|
for(int i=1;i<Z;i++){
|
||||||
|
boolean[] found=new boolean[Z-1];
|
||||||
|
int stor = 1;
|
||||||
|
int count = 0;
|
||||||
|
while(!found[stor-1]){
|
||||||
|
found[stor-1]=true;
|
||||||
|
stor*=i;
|
||||||
|
stor%=Z;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
if(count==Z-1){
|
||||||
|
System.out.println(Z+":\t"+i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void getOrderAndInverse(int Z){
|
||||||
|
for(int i=1; i<Z;i++){
|
||||||
|
System.out.println(i + ":\t" + o(Z,i) + "\t" + inv(Z,i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int o(int Z, int a){
|
||||||
|
int x=1;
|
||||||
|
int stor=1;
|
||||||
|
do{
|
||||||
|
x++;
|
||||||
|
stor*=a;
|
||||||
|
stor%=Z;
|
||||||
|
}while(stor!=1);
|
||||||
|
return x-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int inv(int Z, int a){
|
||||||
|
int x=1;
|
||||||
|
while(((int)a*x%Z)!=1 && x<Z){
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
if(x==Z) return 0;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
}
|
215
src/util/Dump.java
Normal file
215
src/util/Dump.java
Normal file
@ -0,0 +1,215 @@
|
|||||||
|
/*
|
||||||
|
* Stefan Heiss
|
||||||
|
* TH Ostwestfalen-Lippe
|
||||||
|
* FB Elektrotechnik und Technische Informatik
|
||||||
|
* Quellcode zur Lehrveranstaltung Datensicherheit
|
||||||
|
*/
|
||||||
|
package util;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.util.Formatter;
|
||||||
|
|
||||||
|
public class Dump {
|
||||||
|
|
||||||
|
public final static String NL
|
||||||
|
= System.getProperty("line.separator", "\r\n");
|
||||||
|
|
||||||
|
public static byte[] hexString2byteArray(
|
||||||
|
String hexString) {
|
||||||
|
// remove all whitespaces
|
||||||
|
hexString = hexString.replaceAll("\\s", "");
|
||||||
|
hexString = hexString.replaceAll(":", "");
|
||||||
|
|
||||||
|
if ((hexString.length() & 0x01) != 0) {
|
||||||
|
throw new IllegalHexDumpException(
|
||||||
|
"Odd number of nibbles!");
|
||||||
|
}
|
||||||
|
int byteArrayLength = hexString.length() >> 1;
|
||||||
|
byte[] ba = new byte[byteArrayLength];
|
||||||
|
for (int i = 0; i < byteArrayLength; ++i) {
|
||||||
|
try {
|
||||||
|
ba[i]
|
||||||
|
= (byte) Integer.parseInt(
|
||||||
|
hexString.substring(2 * i, 2 * i + 2), 16);
|
||||||
|
} catch (NumberFormatException nfe) {
|
||||||
|
throw new IllegalHexDumpException(
|
||||||
|
"Invalid characters "
|
||||||
|
+ hexString.substring(2 * i, 2 * i + 2)
|
||||||
|
+ " at position " + 2 * i
|
||||||
|
+ " (of streamlined string)!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ba;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------
|
||||||
|
public static String dumpString(int i) {
|
||||||
|
String retString = Integer.toString(i, 16);
|
||||||
|
if ((retString.length() & 0x01) != 0) {
|
||||||
|
retString = "0" + retString;
|
||||||
|
}
|
||||||
|
|
||||||
|
return retString.toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String dumpString(byte b) {
|
||||||
|
return dumpString(b & 0xff);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String dumpString(byte[] data) {
|
||||||
|
return dumpString(data, 0, data.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String dumpString(
|
||||||
|
byte[] data, int offset, int length) {
|
||||||
|
return dumpString(data, "", offset, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String dumpString(
|
||||||
|
byte[] data, String interBytesString,
|
||||||
|
int offset, int length) {
|
||||||
|
if (offset < 0 || length < 0) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Values for offset and parameters must be "
|
||||||
|
+ "non-negative!");
|
||||||
|
}
|
||||||
|
if (data == null) {
|
||||||
|
if (offset > 0 || length > 0) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Specified range not available in data!");
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
if ((offset + length) > data.length) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Specified range not available in data!");
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuffer sb = new StringBuffer(length
|
||||||
|
* (2 + interBytesString.length()));
|
||||||
|
for (int i = offset; i < offset + length; ++i) {
|
||||||
|
if (i != 0) {
|
||||||
|
sb.append(interBytesString);
|
||||||
|
}
|
||||||
|
sb.append(dumpString(data[i]));
|
||||||
|
}
|
||||||
|
return new String(sb);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------
|
||||||
|
public static String dump(BigInteger b) {
|
||||||
|
byte[] data = b.toByteArray();
|
||||||
|
int l = data.length;
|
||||||
|
if (l > 1 && data[0] == 0) {
|
||||||
|
System.arraycopy(data, 1, data, 0, --l);
|
||||||
|
}
|
||||||
|
return dump(data, l);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String dump(byte[] data) {
|
||||||
|
return dump(data, data.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String dump(byte[] data, int length) {
|
||||||
|
StringBuffer sb
|
||||||
|
= new StringBuffer(78 * ((length + 15) >> 4));
|
||||||
|
char[] txt = new char[16];
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for (; i < length;) {
|
||||||
|
if ((i & 0x0f) == 0) {
|
||||||
|
sb.append(alignRight(
|
||||||
|
Integer.toHexString(i) + " ", 9, '0'));
|
||||||
|
}
|
||||||
|
|
||||||
|
int temp = (0xff & data[i]);
|
||||||
|
sb.append(dumpString(temp));
|
||||||
|
sb.append(" ");
|
||||||
|
|
||||||
|
if (temp < 0x20 || temp > 0x7e) /// ???
|
||||||
|
{
|
||||||
|
txt[i++ & 0x0f] = '.';
|
||||||
|
} // if( temp == 0x0a || temp == 0x09 || temp == 0x0d ) /// ???
|
||||||
|
// txt[i++ & 0x0f] = (char)0;
|
||||||
|
else {
|
||||||
|
txt[i++ & 0x0f] = (char) temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((i & 0x0f) == 0) {
|
||||||
|
sb.append(" ");
|
||||||
|
sb.append(txt, 0, 16);
|
||||||
|
sb.append(NL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == 0) // empty data
|
||||||
|
{
|
||||||
|
sb.append("000000 ");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((i = (i & 0x0f)) != 0) {
|
||||||
|
sb.append(fillString(3 * (16 - i), ' ') + " ");
|
||||||
|
sb.append(txt, 0, i);
|
||||||
|
sb.append(NL);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new String(sb.toString().trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return If str.length() < totalLength, a String of
|
||||||
|
* length totalLength is returned. (The original String
|
||||||
|
* extended by specified character from the left.)
|
||||||
|
*/
|
||||||
|
public static String alignRight(
|
||||||
|
String str, int totalLength, char fillChar) {
|
||||||
|
if (totalLength <= str.length()) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
return fillString(totalLength - str.length(), fillChar)
|
||||||
|
+ str;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return If str.length() < totalLength, a String of
|
||||||
|
* length totalLength is returned. (The original String
|
||||||
|
* extended by space characters from the left.)
|
||||||
|
*/
|
||||||
|
public static String alignRight(
|
||||||
|
String str, int totalLength) {
|
||||||
|
return alignRight(str, totalLength, ' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return A String of repLength many repetitions of
|
||||||
|
* specified character.
|
||||||
|
*/
|
||||||
|
public static String fillString(
|
||||||
|
int spaceLength, char fillChar) {
|
||||||
|
if (spaceLength < 0) {
|
||||||
|
spaceLength = 0;
|
||||||
|
}
|
||||||
|
StringBuffer sb = new StringBuffer(spaceLength);
|
||||||
|
for (int i = 0; i < spaceLength; ++i) {
|
||||||
|
sb.append(fillChar);
|
||||||
|
}
|
||||||
|
return new String(sb);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------
|
||||||
|
public static String dumpIntArray(int[] array) {
|
||||||
|
int nosPerLine = 4;
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
Formatter formatter = new Formatter(sb);
|
||||||
|
for (int i = 0; i < array.length; ++i) {
|
||||||
|
if (i != 0 && i % nosPerLine == 0) {
|
||||||
|
sb.append(NL);
|
||||||
|
}
|
||||||
|
formatter.format(" %08x", array[i]);
|
||||||
|
}
|
||||||
|
sb.append(NL);
|
||||||
|
return new String(sb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
15
src/util/IllegalHexDumpException.java
Normal file
15
src/util/IllegalHexDumpException.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* Stefan Heiss
|
||||||
|
* TH Ostwestfalen-Lippe
|
||||||
|
* FB Elektrotechnik und Technische Informatik
|
||||||
|
* Quellcode zur Lehrveranstaltung Datensicherheit
|
||||||
|
*/
|
||||||
|
package util;
|
||||||
|
|
||||||
|
public class IllegalHexDumpException
|
||||||
|
extends IllegalArgumentException {
|
||||||
|
|
||||||
|
public IllegalHexDumpException(String s) {
|
||||||
|
super(s);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user