· 7 years ago · Oct 16, 2018, 01:26 PM
1package com.company;
2
3import java.io.*;
4import java.net.*;
5
6class Main {
7 public static void main(String argv[]) throws Exception {
8 String clientSentence;
9 String capitalizedSentence;
10 ServerSocket welcomeSocket = new ServerSocket(6789);
11
12 Socket connectionSocket = welcomeSocket.accept();
13 BufferedReader inFromClient =
14 new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
15 DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
16 clientSentence = inFromClient.readLine();
17 final String secretKey = "ssshhhhhhhhhhh!!!!";
18 String originalString = "howtodoinjava.com";
19 String encryptedString = Main2.encrypt(originalString, secretKey) ;
20 String decryptedString = Main2.decrypt(clientSentence, secretKey);
21 System.out.println("Received: " + clientSentence);
22 capitalizedSentence = clientSentence.toUpperCase() + 'n';
23 outToClient.writeBytes(capitalizedSentence);
24
25 System.out.println(clientSentence);
26
27 System.out.println(originalString);
28 System.out.println(encryptedString);
29 System.out.println(decryptedString);
30 }
31}