Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.lang.*;
- public class Main
- {
- static int pass = 0;
- static String ans, backup;
- static Scanner sc = new Scanner(System.in);
- public static String decrypt(String backup)
- {
- int temp, len = backup.length(), i = 0;
- char ans2[] = new char[len];
- char x;
- while (i < len)
- {
- if (pass > 50)
- pass = 0;
- temp = backup.charAt(i);
- temp -= pass;
- x = (char)temp;
- ans2[i] = x;
- i++;
- pass++;
- }
- ans2[len] = '\0';
- return String.valueOf(ans2);
- }
- public static String decryptv2()
- {
- String f;
- System.out.println("Enter the name(with extension) of file you want to open.\n\n\t");
- f = sc.next();
- try
- {
- File file = new File(f);
- BufferedReader br = new BufferedReader(new FileReader(file));
- String str = "", s;
- while ((s = br.readLine()) != null)
- str += s;
- br.close();
- return decrypt(str);
- }
- catch (Exception e)
- {
- System.out.println("File not found");
- return "";
- }
- }
- public static void save(StringBuilder backup)
- {
- String f;
- System.out.println("Enter the name of the file(with extension)\n\n\t");
- f = sc.next();
- try
- {
- FileWriter file = new FileWriter(f);
- file.write(backup.toString());
- System.out.println("The text is succesfully saved in a file named \"" + f + "\"" + (char)24 + "\n\n\t");
- file.close();
- System.in.read();
- }
- catch (Exception e)
- {
- System.out.println("Error occurred while saving the file.");
- }
- }
- public static void save2(StringBuilder backup)
- {
- String f;
- System.out.println("Enter the name of the file(with extension)\n\n\t");
- f = sc.next();
- try
- {
- FileWriter file = new FileWriter(f);
- file.write(backup.toString());
- System.out.println("The text is succesfully saved in a file named \"" + f + "\"" + (char)24 + "\n\n\t");
- file.close();
- System.in.read();
- }
- catch (Exception e)
- {
- System.out.println("Error occurred while saving the file.");
- }
- }
- public static String encrypt(String str)
- {
- int len, i = 0, temp;
- len = str.length();
- char enc[] = new char[len];
- char x;
- while (i < len)
- {
- if (pass > 50)
- pass = 0;
- temp = str.charAt(i);
- temp += pass;
- x = (char)temp;
- enc[i] = x;
- i++;
- pass++;
- }
- enc[len] = '\0';
- pass = 0;
- backup = String.valueOf(enc);
- return String.valueOf(enc);
- }
- public static void encryptv2()
- {
- System.out.println("Enter the Filename(with extension).\n\n\t");
- String str = "", f;
- f = sc.next();
- try
- {
- File file = new File(f);
- BufferedReader br = new BufferedReader(new FileReader(file));
- while (br.ready())
- str += br.readLine();
- br.close();
- backup = encrypt(str);
- }
- catch (Exception e)
- {
- System
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement