Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //package mixed_cipher;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.lang.String;
- import javax.swing.*;
- public class Mixed {
- static String pln = "abcdefghijklmnopqrstuvwxyz";
- public static void main(String[] args) {
- // TODO Auto-generated constructor stub
- JFrame frame = new JFrame("Mixed");
- frame.setLayout(new GridLayout(4, 2));
- frame.setSize(500, 150);
- JTextField plaintext = new JTextField();
- JTextField ciphertext = new JTextField();
- JLabel plaintxt = new JLabel("Plaintext");
- JLabel ciphertxt = new JLabel("Ciphertext");
- JLabel encrypted = new JLabel("Encrypted");
- JLabel decrypted = new JLabel("Decrypted");
- JButton encrypt = new JButton("Encrypt");
- JButton decrypt = new JButton("Decrypt");
- frame.add(plaintxt);
- frame.add(plaintext);
- frame.add(ciphertxt);
- frame.add(ciphertext);
- frame.add(encrypt);
- frame.add(encrypted);
- frame.add(decrypt);
- frame.add(decrypted);
- frame.setVisible(true);
- encrypt.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent arg0) {
- String plain = plaintext.getText().toString();
- String cph = ciphertext.getText().toString();
- String ciph = "";
- String encpt = "";
- for(int i = 0; i < cph.length(); ++i) {
- if(ciph.indexOf(cph.charAt(i)) == -1){
- ciph += cph.charAt(i);
- }
- }
- for(int i = 0; i < pln.length(); ++i) {
- if(ciph.indexOf(pln.charAt(i)) == -1){
- ciph += pln.charAt(i);
- }
- }
- for(int i = 0; i < plain.length(); ++i) {
- encpt += ciph.charAt(pln.indexOf(plain.charAt(i)));
- }
- encrypted.setText(encpt);
- }
- });
- decrypt.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent arg0) {
- // TODO Auto-generated method stub
- String cph = ciphertext.getText().toString();
- String ciph = "";
- String decpt = "";
- for(int i = 0; i < cph.length(); ++i) {
- if(ciph.indexOf(cph.charAt(i)) == -1){
- ciph += cph.charAt(i);
- }
- }
- for(int i = 0; i < pln.length(); ++i) {
- if(ciph.indexOf(pln.charAt(i)) == -1){
- ciph += pln.charAt(i);
- }
- }
- for(int i = 0; i < encrypted.getText().length(); ++i) {
- decpt += pln.charAt(ciph.indexOf(encrypted.getText().charAt(i)));
- }
- decrypted.setText(decpt);
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement