-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEncryptor.java
More file actions
executable file
·67 lines (51 loc) · 1.47 KB
/
Encryptor.java
File metadata and controls
executable file
·67 lines (51 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import java.net.Socket;
import java.io.*;
/**
Goal of this class is to open up a connection with the decryptor, and send an encoded message with some specified a and n
*/
public class Encryptor{
Socket connToDecryptor;
public static void main(String [] args)
{
if (args.length != 5)
{
System.out.println("Usage Encryptor <message> <n> <a> <ip> <port>");
}
String message = args[0];
String n = args[1];
String a = args[2];
Encryptor enc = new Encryptor();
enc.connectToDecryptor(args[3],args[4]);
RSAencrypt messageEncryptor = new RSAencrypt(message,n,a);
Message sendableMessage = messageEncryptor.getMessage();
enc.sendToDecryptor(sendableMessage);
}
public void connectToDecryptor(String IP, String port)
{
try{
Socket connToDecryptorTemp = new Socket(IP, Integer.parseInt(port));
connToDecryptor = connToDecryptorTemp;
}
catch (NumberFormatException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void sendToDecryptor(Message sendable){
byte [] decodedMsg = sendable.convertToSendable();
int len = sendable.getLen();
OutputStream output;
try {
output = connToDecryptor.getOutputStream();// get the outputStream to send through
String x = new String(decodedMsg);
output.write(decodedMsg,0,decodedMsg.length);//send
} catch (IOException e) {
e.printStackTrace();
}
try {
connToDecryptor.close();
}
catch (IOException e)
{}
}
}