Browse Source

Solved assignment

crypto-a4
Thomas Johnson 2 years ago
parent
commit
ba5c7c7c14
  1. 1
      crypto/result.txt
  2. 65
      sample/Main.java

1
crypto/result.txt

@ -0,0 +1 @@
a = 7043898314006318326115940780032836020708457705643306740966786874458975733455837047675402416635877437320813967832253932800054266068442549850174403900383164

65
sample/Main.java

@ -1,23 +1,56 @@
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import crypto.*;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(root, 300, 275));
primaryStage.show();
}
import java.io.BufferedReader;
import java.io.FileReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
try
{
WeierstrassCurve curve = new WeierstrassCurve(
new BigInteger("106232669604492000952101983011424051981376980857635143588066911520770063114189"),
new BigInteger("76587977420977035044598204053610304596633008638205335306823124689977025819271"),
new BigInteger("73482936276013145955565144225861612903052378488799025581459884388790895646531")
);
WeierstrassPoint g = new WeierstrassPoint(curve,
new BigInteger("10653634968474602131259680612117761410240294893518819057928307519545438935105"),
new BigInteger("53590057826264431726814016302376375223987987950117371742659725930948430562791")
);
WeierstrassPoint p = new WeierstrassPoint(curve,
new BigInteger("28532308240163403308957388634927833383486854937647900059668124240434058298343"),
new BigInteger("69104332354999776650513976089584444069941586735957501584816228392545085961665")
);
public static void main(String[] args) {
launch(args);
if (p.equals(g.mult(new BigInteger("3"))))
System.out.println("equality detected");
BufferedReader br = new BufferedReader(new FileReader("/mnt/home/thajohns/cs242/cs242-project/src/crypto/a4.cipher"));
String line = br.readLine();
ArrayList<Byte> bytes = new ArrayList();
while (line != null)
{
Scanner s = new Scanner(line);
WeierstrassPoint c = new WeierstrassPoint(curve, new BigInteger(s.next()), new BigInteger(s.next()));
WeierstrassPoint h = new WeierstrassPoint(curve, new BigInteger(s.next()), new BigInteger(s.next()));
WeierstrassPoint f = h.mult(new BigInteger(new byte[]{3}));
WeierstrassPoint m = c.add(f.inv());
System.out.println(m.x.toString() + " " + m.y.toString());
bytes.add((byte) m.x.intValue());
line = br.readLine();
}
for (byte b : bytes)
{
System.out.print((char) b);
}
} catch (Exception e)
{
e.printStackTrace();
}
}
}
Loading…
Cancel
Save