Verified Commit 4e4416c4 authored by Jon Felix Germinian's avatar Jon Felix Germinian
Browse files

init

parents
I am the bone of my sword
Steel is my body and fire is my blood
I have created over a thousand blades
Unknown to Death,
Nor known to Life.
Have withstood pain to create many weapons
Yet, those hands will never hold anything
So as I pray, Unlimited Blade Works.
\ No newline at end of file
# Tucil 1 IF4020
How to run
`python app.py`
requirements:
- pyqt5
\ No newline at end of file
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'app.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
import sys
import os
from PyQt5 import QtCore, QtGui, QtWidgets
from vigenere import Vigenere
from full_vigenere import FullVigenere
from running_vigenere import RunningVigenere
from playfair import Playfair
from util import plaintext5
class Ui_MainWIndow(object):
def setupUi(self, MainWIndow):
MainWIndow.setObjectName("MainWindow")
MainWIndow.resize(929, 852)
self.output = ''
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.outputBox = QtWidgets.QTextBrowser(self.centralwidget)
self.outputBox.setGeometry(QtCore.QRect(20, 480, 501, 281))
self.outputBox.setObjectName("outputBox")
self.labelOutput = QtWidgets.QLabel(self.centralwidget)
self.labelOutput.setGeometry(QtCore.QRect(20, 440, 141, 41))
font = QtGui.QFont()
font.setPointSize(20)
self.labelOutput.setFont(font)
self.labelOutput.setObjectName("labelOutput")
self.saveButton = QtWidgets.QPushButton(self.centralwidget)
self.saveButton.setGeometry(QtCore.QRect(530, 480, 88, 28))
self.saveButton.setObjectName("saveFile")
self.saveButton.clicked.connect(self.saveFile)
self.inputBox = QtWidgets.QPlainTextEdit(self.centralwidget)
self.inputBox.setGeometry(QtCore.QRect(20, 60, 501, 281))
self.inputBox.setAutoFillBackground(False)
self.inputBox.setPlainText("")
self.inputBox.setObjectName("inputBox")
self.cipherType = QtWidgets.QGroupBox(self.centralwidget)
self.cipherType.setGeometry(QtCore.QRect(680, 210, 231, 311))
font = QtGui.QFont()
font.setPointSize(15)
self.cipherType.setFont(font)
self.cipherType.setObjectName("cipherType")
self.vigenere = QtWidgets.QRadioButton(self.cipherType)
self.vigenere.setGeometry(QtCore.QRect(0, 40, 151, 31))
self.vigenere.setChecked(True)
self.vigenere.setObjectName("vigenere")
self.vigenereFull = QtWidgets.QRadioButton(self.cipherType)
self.vigenereFull.setGeometry(QtCore.QRect(0, 70, 161, 31))
self.vigenereFull.setObjectName("vigenereFull")
self.vigenereRunning = QtWidgets.QRadioButton(self.cipherType)
self.vigenereRunning.setGeometry(QtCore.QRect(0, 100, 191, 31))
self.vigenereRunning.setObjectName("vigenereRunning")
self.playfair = QtWidgets.QRadioButton(self.cipherType)
self.playfair.setGeometry(QtCore.QRect(0, 130, 191, 31))
self.playfair.setObjectName("playfair")
self.encryptButton = QtWidgets.QPushButton(self.cipherType)
self.encryptButton.setGeometry(QtCore.QRect(10, 200, 121, 41))
self.encryptButton.setObjectName("encryptButton")
self.encryptButton.clicked.connect(self.encrypt)
self.decryptButton = QtWidgets.QPushButton(self.cipherType)
self.decryptButton.setGeometry(QtCore.QRect(10, 260, 121, 41))
self.decryptButton.setObjectName("decryptButton")
self.decryptButton.clicked.connect(self.decrypt)
self.uploadFile = QtWidgets.QPushButton(self.centralwidget)
self.uploadFile.setGeometry(QtCore.QRect(530, 70, 88, 28))
self.uploadFile.setObjectName("uploadFile")
self.uploadFile.clicked.connect(self.openFile)
self.labelInput = QtWidgets.QLabel(self.centralwidget)
self.labelInput.setGeometry(QtCore.QRect(20, 20, 141, 41))
font = QtGui.QFont()
font.setPointSize(20)
self.labelInput.setFont(font)
self.labelInput.setObjectName("labelInput")
self.keyBox = QtWidgets.QPlainTextEdit(self.centralwidget)
self.keyBox.setGeometry(QtCore.QRect(130, 350, 391, 41))
self.keyBox.setAutoFillBackground(False)
self.keyBox.setPlainText("")
self.keyBox.setObjectName("keyBox")
self.labelKey = QtWidgets.QLabel(self.centralwidget)
self.labelKey.setGeometry(QtCore.QRect(60, 350, 57, 41))
font = QtGui.QFont()
font.setPointSize(15)
self.labelKey.setFont(font)
self.labelKey.setObjectName("labelKey")
MainWIndow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWIndow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 929, 24))
self.menubar.setObjectName("menubar")
MainWIndow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWIndow)
self.statusbar.setObjectName("statusbar")
MainWIndow.setStatusBar(self.statusbar)
self.groupBox1 = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox1.setGeometry(QtCore.QRect(530, 520, 120, 80))
self.groupBox1.setTitle("")
self.groupBox1.setObjectName("groupBox")
self.spaceButton = QtWidgets.QRadioButton(self.groupBox1)
self.spaceButton.setGeometry(QtCore.QRect(0, 20, 97, 24))
self.spaceButton.setChecked(False)
self.spaceButton.setObjectName("spaceButton")
self.spaceButton.toggled.connect(self.space5)
self.plainButton = QtWidgets.QRadioButton(self.groupBox1)
self.plainButton.setGeometry(QtCore.QRect(0, 50, 97, 24))
self.plainButton.setCheckable(True)
self.plainButton.setChecked(True)
self.plainButton.setObjectName("plainButton")
self.plainButton.toggled.connect(self.plainoutput)
self.retranslateUi(MainWIndow)
QtCore.QMetaObject.connectSlotsByName(MainWIndow)
def retranslateUi(self, MainWIndow):
_translate = QtCore.QCoreApplication.translate
MainWIndow.setWindowTitle(_translate("MainWIndow", "Tucil 1 IF4020"))
self.labelOutput.setText(_translate("MainWIndow", "Output"))
self.saveButton.setText(_translate("MainWIndow", "Save File"))
self.spaceButton.setText(_translate("MainWIndow", "With space"))
self.plainButton.setText(_translate("MainWIndow", "Plain"))
self.cipherType.setTitle(_translate("MainWIndow", "Cipher Type"))
self.vigenere.setText(_translate("MainWIndow", "Vigenere"))
self.vigenereFull.setText(_translate("MainWIndow", "Full Vigenere"))
self.vigenereRunning.setText(_translate("MainWIndow", "Running Vigenere"))
self.playfair.setText(_translate("MainWIndow", "Playfair"))
self.encryptButton.setText(_translate("MainWIndow", "Encrypt"))
self.decryptButton.setText(_translate("MainWIndow", "Decrypt"))
self.uploadFile.setText(_translate("MainWIndow", "Upload File"))
self.labelInput.setText(_translate("MainWIndow", "Input"))
self.labelKey.setText(_translate("MainWIndow", "Key"))
def openFile(self):
filename = QtWidgets.QFileDialog.getOpenFileName(parent=None, caption='Open File', directory=os.getcwd(), filter="Text files (*.txt)")
if filename[0]:
f = open(filename[0],'r')
with f:
data = f.read()
self.inputBox.setPlainText(data)
def saveFile(self):
filename = QtWidgets.QFileDialog.getSaveFileName(None, 'Save File')
if filename[0]:
f = open(filename[0],'w')
text = self.outputBox.toPlainText()
f.write(text)
f.close()
def encrypt(self):
key = self.keyBox.toPlainText()
if self.vigenere.isChecked():
v = Vigenere()
ciphertext = v.encrypt(self.inputBox.toPlainText(),key)
elif self.vigenereFull.isChecked():
fv = FullVigenere()
ciphertext = fv.encrypt(self.inputBox.toPlainText(), key)
elif self.vigenereRunning.isChecked():
rv = RunningVigenere()
ciphertext = rv.encrypt(self.inputBox.toPlainText())
elif self.playfair.isChecked():
pf = Playfair()
ciphertext = pf.encrypt(self.inputBox.toPlainText(), key)
self.output = ciphertext
self.outputBox.setText(ciphertext)
self.plainButton.setChecked(True)
def decrypt(self):
key = self.keyBox.toPlainText()
if self.vigenere.isChecked():
v = Vigenere()
plaintext = v.decrypt(self.inputBox.toPlainText(),key)
elif self.vigenereFull.isChecked():
fv = FullVigenere()
plaintext = fv.decrypt(self.inputBox.toPlainText(), key)
elif self.vigenereRunning.isChecked():
rv = RunningVigenere()
plaintext = rv.decrypt(self.inputBox.toPlainText())
elif self.playfair.isChecked():
pf = Playfair()
plaintext = pf.decrypt(self.inputBox.toPlainText(), key)
self.output = plaintext
self.outputBox.setText(plaintext)
self.plainButton.setChecked(True)
def space5(self):
text = plaintext5(self.output)
self.outputBox.setText(text)
def plainoutput(self):
self.outputBox.setText(self.output)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWIndow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWIndow</class>
<widget class="QMainWindow" name="MainWIndow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>929</width>
<height>852</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QTextBrowser" name="outputBox">
<property name="geometry">
<rect>
<x>20</x>
<y>480</y>
<width>501</width>
<height>281</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="labelOutput">
<property name="geometry">
<rect>
<x>20</x>
<y>440</y>
<width>141</width>
<height>41</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>20</pointsize>
</font>
</property>
<property name="text">
<string>Output</string>
</property>
</widget>
<widget class="QPushButton" name="saveFile">
<property name="geometry">
<rect>
<x>530</x>
<y>480</y>
<width>88</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>Save File</string>
</property>
</widget>
<widget class="QPlainTextEdit" name="inputBox">
<property name="geometry">
<rect>
<x>20</x>
<y>60</y>
<width>501</width>
<height>281</height>
</rect>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="plainText">
<string/>
</property>
</widget>
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>530</x>
<y>50</y>
<width>120</width>
<height>80</height>
</rect>
</property>
<property name="title">
<string/>
</property>
<widget class="QRadioButton" name="fileButton">
<property name="geometry">
<rect>
<x>0</x>
<y>20</y>
<width>97</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>File</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
<widget class="QRadioButton" name="textButton">
<property name="geometry">
<rect>
<x>0</x>
<y>50</y>
<width>97</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>Text</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="cipherType">
<property name="geometry">
<rect>
<x>680</x>
<y>210</y>
<width>231</width>
<height>311</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>15</pointsize>
</font>
</property>
<property name="title">
<string>Cipher Type</string>
</property>
<widget class="QRadioButton" name="vigenere">
<property name="geometry">
<rect>
<x>0</x>
<y>40</y>
<width>151</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Vigenere</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<widget class="QRadioButton" name="vigenereFull">
<property name="geometry">
<rect>
<x>0</x>
<y>70</y>
<width>161</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Full Vigenere</string>
</property>
</widget>
<widget class="QRadioButton" name="vigenereRunning">
<property name="geometry">
<rect>
<x>0</x>
<y>100</y>
<width>191</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Running Vigenere</string>
</property>
</widget>
<widget class="QRadioButton" name="playfair">
<property name="geometry">
<rect>
<x>0</x>
<y>130</y>
<width>191</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>Playfair</string>
</property>
</widget>
<widget class="QPushButton" name="encryptButton">
<property name="geometry">
<rect>
<x>10</x>
<y>200</y>
<width>121</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Encrypt</string>
</property>
</widget>
<widget class="QPushButton" name="decryptButton">
<property name="geometry">
<rect>
<x>10</x>
<y>260</y>
<width>121</width>
<height>41</height>
</rect>
</property>
<property name="text">
<string>Decrypt</string>
</property>
</widget>
</widget>
<widget class="QPushButton" name="uploadFile">
<property name="geometry">
<rect>
<x>530</x>
<y>150</y>
<width>88</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>Upload File</string>
</property>
</widget>
<widget class="QLabel" name="labelInput">
<property name="geometry">
<rect>
<x>20</x>
<y>20</y>
<width>141</width>
<height>41</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>20</pointsize>
</font>
</property>
<property name="text">
<string>Input</string>
</property>
</widget>
<widget class="QPlainTextEdit" name="keyBox">
<property name="geometry">
<rect>
<x>130</x>
<y>350</y>
<width>391</width>
<height>41</height>
</rect>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="plainText">
<string/>
</property>
</widget>
<widget class="QLabel" name="labelKey">
<property name="geometry">
<rect>
<x>60</x>
<y>350</y>
<width>57</width>
<height>41</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>15</pointsize>
</font>
</property>
<property name="text">
<string>Key</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>929</width>
<height>24</height>
</rect>
</property>
</widget>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
from vigenere import Vigenere
alphabets = 'HZOIDWBXMRYGFQPTEUSLVACKJN'
class FullVigenere(Vigenere):
def __init__(self):
self.final_table = [alphabets[i:]+alphabets[:i] for i in range(len(alphabets))]
# text = 'nakano miku is so cute'
# key = 'holo'
# fv = FullVigenere()
# ct = fv.encrypt(text, key)
# print(ct)
# print(fv.decrypt(ct,key))
\ No newline at end of file
class Playfair:
def matrix(self, x, y, initial):
return [[initial for i in range(x)] for j in range(y)]
def keymatrix(self, key):
key = self.process_text(key)
result = list()
flag = 0
k = 0
key_matrix = self.matrix(5, 5, 0)
for c in key:
if c not in result:
if c == 'J':
result.append('I')
else:
result.append(c)
for i in range(65, 91):
if chr(i) not in result:
if i == 73 and chr(74) not in result:
result.append("I")
flag = 1
elif flag == 0 and i == 73 or i == 74:
pass
else:
result.append(chr(i))
for i in range(0, 5):
for j in range(0, 5):
key_matrix[i][j] = result[k]
k += 1