package encryptie1;
import java.io.PrintStream;
import java.util.Scanner;
public class Encryptie1 {
static final String ALL_SYMBOLS = "abcdefghijklmnopqrstuvwxyz";
static final String UNENCRYPTED_TEXT = "Rot13 is een simpel encryptiealgoritme. Het behoort tot de Caesarrotaties (waarbij een alfabet gebruikt wordt dat een aantal plaatsen verschoven is). Het idee is om letters dertien plaatsen op te schuiven in het alfabet, en bij de Z weer terug te gaan naar de A. Wikipedia wordt bijvoorbeeld Jvxvcrqvn. Door Rot13 nogmaals op de tekst toe te passen is de originele tekst weer terug te krijgen. Dezelfde functie is dus bruikbaar voor zowel coderen als decoderen. Via de volgende tabel kan Rot13 vertaald worden. A B C D E F G H I J K L M N O P Q R S T U V W X Y Z - N O P Q R S T U V W X Y Z A B C D E F G H I J K L M Als encryptie is Rot13 weinig waard, maar het wordt op Usenet gebruikt om bijvoorbeeld clues te verbergen. Het wordt ook gebruikt bij sommige spelletjes op internet.";
static final boolean USE_UNENCRYPTED_TEXT = true;
PrintStream out;
Scanner in;
Encryptie1() {
out = new PrintStream(System.out);
in = new Scanner(System.in);
}
String generateKey(String unencryptedSymbols) {
out.print("Generating key... ");
String encryptedSymbols = "";
int currentRandomNumber;
StringBuilder temporaryStringBuilder;
for(int i=0; 0<unencryptedSymbols.length(); i++){
currentRandomNumber = (int)(Math.random()*(26-i));
encryptedSymbols += unencryptedSymbols.charAt( currentRandomNumber );
temporaryStringBuilder = new StringBuilder(unencryptedSymbols);
unencryptedSymbols = temporaryStringBuilder.deleteCharAt(currentRandomNumber).toString();
//out.printf("\n%d - %s - %s", currentRandomNumber, encryptedSymbols, unencryptedSymbols);
}
out.print("Finished");
//out.printf(": %s\n", encryptedSymbols);
return encryptedSymbols;
}
String scanMultipleLines() {
String allLines = "";
if(USE_UNENCRYPTED_TEXT!=true){
out.print("Stop hier de tekst die encrypted moet worden: \n");
while(in.hasNext()){
allLines += in.nextLine();
}
}else{
allLines = UNENCRYPTED_TEXT;
}
return allLines;
}
void showEncryptionKeyTranslations(String encryptionKey){
int currentCharIndex;
char currentChar;
char newChar;
out.print("\n\n");
for(int i=32; i<127; i++){
out.print((char)(i));
}
out.print("\n");
for(int i=32; i<127; i++){
currentChar = (char) i;
currentCharIndex = (int) currentChar;
//out.printf("\nc: %c, d: %d", currentChar, (int)currentChar);
if(96<currentChar&¤tChar<123){
newChar = encryptionKey.charAt(currentCharIndex-97);
out.print(newChar);
//out.printf("\nc: '%c'->'%c', d: %d->%d", currentChar, newChar, currentCharIndex, currentCharIndex-97);
}else if(64<currentChar&¤tChar<91){
newChar = (char) (encryptionKey.charAt(currentCharIndex-65)-32);
out.print(newChar);
//out.printf("\nc: '%c'->'%c', d: %d->%d", currentChar, newChar, currentCharIndex, currentCharIndex-65);
}else{
out.print(currentChar);
//out.printf("\nc: '%c'->'%c'", currentChar, currentChar);
}
}
}
String encrypt(String unencryptedString, String encryptionKey) {
out.print("\nEncrypting text... ");
String encryptedString = "";
int currentCharIndex;
char currentChar;
for(int i=0; i<unencryptedString.length(); i++){
currentChar = unencryptedString.charAt(i);
currentCharIndex = (int) currentChar;
//out.printf("\nc: %c, d: %d", currentChar, (int)currentChar);
if(96<currentChar&¤tChar<123){
encryptedString += encryptionKey.charAt(currentCharIndex-97);
//out.printf("\nc: '%c', d: %d->%d, \ts: %s", currentChar, currentCharIndex, currentCharIndex-97, encryptedString);
}else if(64<currentChar&¤tChar<91){
encryptedString += (char) (encryptionKey.charAt(currentCharIndex-65)-32);
//out.printf("\nc: '%c', d: %d->%d, \ts: %s", currentChar, currentCharIndex, currentCharIndex-65, encryptedString);
}else{
encryptedString += currentChar;
//out.printf("\nc: '%c'\t\t\ts: %s", currentChar, encryptedString);
}
//out.printf("\nc: %c", unencryptedString.charAt(i));
//out.printf("\nd: %d", unencryptedString.charAt(i)-97);
//out.printf("%c", encryptionKey.charAt((int)(unencryptedString.charAt(i)-97)));
}
out.print("Finished");
return encryptedString;
}
void start(){
String key = generateKey(ALL_SYMBOLS);
String unencrypted = scanMultipleLines();
String encrypted = encrypt(unencrypted, key);
out.printf("\n\n%s", encrypted);
//showEncryptionKeyTranslations(key);
}
public static void main(String[] args){
new Encryptie1().start();
}
}
About Online Java Compiler
Try our Online Java Compiler (Version OpenJDK 11.0.17) to Edit, Run, and Share your Java Code directly from your browser. This online development environment provides you the latest version OpenJDK 11.0.17.
How to use Online Java Compiler?
Write and Execute Code
- Write your program (or, paste it) directly under the "Source Code" tab.
- If you want to save your program, go to the "Project" menu and save it.
- You can directly execute your program without saving it by clicking on on "Execute" button.
User Input
The latest version of Coding Ground allows to provide program input at run time from the termnial window exactly the same way as you run your program at your own computer. So simply run a program and provide your program input (if any) from the terminal window available in the right side.
Online Java Compiler: Keyboard Shortcuts
The following are the keyword shortcut of this Online Java Compiler:
Shortcut | Description |
⌘ + Enter | Run the program |
⌘ + S | Save Project (Login Required) |
⇧ + ⌘ + S | Save As Project |
⌘ + P | New Project |
⌘ + G | Share Project |
⌘ + Z | Undo Editing |
⌘ + Y | Redo Editing |
⌘ + A | Select All Text |
⌘ + X | Cut Selected Text |
⌘ + C | Copy Selected Text |
⌘ + V | Paste Copied Text |
⌘ + F | Search Text |
⌘ + ⌥ + F | Replace Text |
Shortcut | Description |
Ctrl + Enter | Run the program |
Ctrl + S | Save Project |
Shift + Ctrl + S | Save As Project |
Ctrl + G | Share Project |
Ctrl + Z | Undo Editing |
Ctrl + Y | Redo Editing |
Ctrl + A | Select All Text |
Ctrl + X | Cut Selected Text |
Ctrl + C | Copy Selected Text |
Ctrl + V | Paste Copied Text |
Ctrl + F | Search Text |
Ctrl + H | Replace Text |
Online Java Compiler: Save and Share Java Code (Project)
Save Java Project Online
You can save your Java Project with us so that you can access this project later on. To save a project you will need to create a login Id with us. So before you save a project, please create a login Id using a link given at the top right corner of this page.
Share Java Project Online
You can use this feature to share your Java Code with your teachers, classmates and colleagues. Just click Share Button and it will create a short link, which can be shared through Email, WhatsApp or even through Social Media. A shared link will be deleted if it has been passive for almost 3 months.
More Features of Online Java Compiler
- Theme – You can change the current editor's theme from the "Editor Theme" option under "Settings" menu.
- Font Size – You can change the font size of the editor /compiler from from the "Font Size" option under "Settings" menu.
- Tab Size – You can change the tab size from the "Tab Size" option under "Settings" Menu.
- Show/Hide Line Numbers – You can show/hide the line number with the code from the "Show Line Numbers" or "Hide Line Numbers" option under "Settings" Menu.
- And, many more.
Benefits of Using Online Java Compiler
There are several benefits of using the Online Java Compiler to run your Java code:
- Platform independence: You can run your code from any device without taking care of operating systems.
- Convenience: You don't need to install anything for using this.
- No setup required: There is no need for additional setup to run your code.
- Updated version: Our online compiler/editors/terminals are the latest up-to-date.