Skip to content

Instantly share code, notes, and snippets.

@extremecoders-re
Created October 17, 2017 06:21
Show Gist options
  • Save extremecoders-re/f8258764d38133d435a0f1ae053a1a0d to your computer and use it in GitHub Desktop.
Save extremecoders-re/f8258764d38133d435a0f1ae053a1a0d to your computer and use it in GitHub Desktop.
Flare-On 4 Challenge #10 decryption tool
import string
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys
import ui_mainwindow
encoded = 'QAYLHhIJbzIQClFAQgQTFkNYbz5aUBQZURIXXBARFztifGQwPRdaaFkePE9KOjMWRBRdUhtDXkIXaGkpYTc6REs7UgB6AAAATQ1FUUlOU0dWEylVOSlzfDJUGwwaXAMCeWZeXnsHSztPGn0LXnp9DlAUWksWUloCH1JaJjV0c04cLApTdR9SWiY1dHNOB1Q4XQEEJF1Fc3QyQUhBSit3Enp9Vi1UB3lEHQAABRRQXg4LPTsOT1JHBl8tN0kEQVsMRUc6EE1HMDQqe3MIYxdgFU4YRh5bX2llARVCbFwZOAYRHQJhJX52dkpwd3MaZkpvE0hTYVcUdmgyYlx4MBI4JHJ5BzAyGx03LRx9AHUqLgkAcFUiLgwcFD4+FAY+Ij4dOzoLCwAYSgciNQ0NLS0QGw91FAQ0bgULMRQCFjxKCgAzIjoMMBsKGxlmGBJJBAoWEC5XDy5sEDcuHBADBz0kGRUAERw9CyMQFDkbGBUtMhUmcQwEAhsSBiEMCyhdVSUEJjZUHiUqGg8mahAYFAwbEDIqURg9dAohDz4xFwk+MRxdMQQHLi4QAgAABhAXEHMHKnUTGXEmMhc+CwouSwgvCARhdwQAHFsKInkWGC4qOwANIWQWOnUbHzMqMQF4MQcSWil3DisqMRErCz8wEj5RFS1TNjtbXjACHyEyDABdKQQ/aQoXFWR3GiIpARMsPSYUMAwUAgdHZBQGKS8FAAAoAQEfUho/egUxKD4xJBFXBx4QCCAiKFpwGzU+AA1IATEOLgsTFGZBLAQbMj8VO2M9BS5ZLwMuJmIEEwMMGQAuRyNbRQASAEclIHMyPCM4dgAKLj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B0k9DV0QFFdZBQpMFwYeVEUZC01XB1UWFBkRHwIEAAgcCh8CPQkCEh8NSh4PEA4eGFsaGXoo'
#encoded = "IBZDEA0DYRFOEEgKRkUaDEVPAkENREVZCxRZTVIcTwZPDRcJWVMdCRYcFk4BDBEcCk4VBhBMHE8THVJTDAwWF1MAVQINAVMKTxQcREYYBhkHUgNPSS0bFkVaSCROF08bBgBSUxYAG0UARRgDHFoXRRUECA5JAA0HFFRNQxoKBVRBFwsEBFgAFQYFVEVOFQsDUggaEUUTGgAARUkaHA5UWQYbBk9XFh0eUkUDBxsIDEUNBxxDW0kVA1VTAwgeGAAREQgcEwAREAoNAlMAExYPS1MyFVUAQU4mU0EfTxcIVUERTBgCEAANGAkIF1NPEgcXUgdIA08ARRUbCk5SHA4GTw9SHAFSVEEFDQtVEQAOBxBSEkEXG1VUGEEMEQxUFk8XRVtJFQNVQRseDRVTQQ4SQRhTRgMMTBRSA08="
KEYLEN = 64
keymap = {}
class MainWindow(QMainWindow, ui_mainwindow.Ui_MainWindow):
def __init__(self, parent=None):
QMainWindow.__init__(self)
# super(MainWindow, self).__init__(parent)
self.setupUi(self)
ct = map(ord, list(encoded.decode('base64')))
self.plainTextEdit.setPlainText(''.join(map(chr, ct)))
@pyqtSlot()
def on_plainTextEdit_cursorPositionChanged(self):
visualOffset = self.plainTextEdit.textCursor().position()
lineno = self.plainTextEdit.textCursor().blockNumber()
actualOffset = visualOffset + lineno
moddedOffset = actualOffset % KEYLEN
self.spinBox_2.setValue(lineno)
self.spinBox_3.setValue(actualOffset)
self.spinBox.setValue(moddedOffset)
if moddedOffset in keymap.keys():
self.lineEdit.setText(chr(keymap[moddedOffset]))
else:
self.lineEdit.setText('NONE')
@pyqtSlot(int)
def on_spinBox_3_valueChanged(self, value):
actualOffset = value
moddedOffset = actualOffset % KEYLEN
self.spinBox.setValue(moddedOffset)
if actualOffset in keymap.keys():
self.lineEdit.setText(chr(keymap[actualOffset]))
else:
self.lineEdit.setText('NONE')
@pyqtSlot()
def on_pushButton_clicked(self, *args):
ct = map(ord, list(encoded.decode('base64')))
actualOffset = self.spinBox_3.value()
actualOffset %= KEYLEN
if str(self.lineEdit.text()) == 'CR':
char = ord('\r')
elif str(self.lineEdit.text()) == 'LF':
char = ord('\n')
elif str(self.lineEdit.text()) == 'TAB':
char = ord('\t')
elif len(self.lineEdit.text()) > 1:
return
else:
char = ord(str(self.lineEdit.text()))
ct_display = [chr(2)] * len(ct)
keymap[actualOffset] = char
for p in keymap.keys():
v = keymap[p]
ct[p] = v
ct_display[p] = chr(v)
for i in xrange(p+KEYLEN, len(ct), KEYLEN):
ct[i] ^= v
ct_display[i] = chr(ct[i])
v = ct[i]
self.disconnect(self.plainTextEdit, SIGNAL('cursorPositionChanged()'), self.on_plainTextEdit_cursorPositionChanged)
self.plainTextEdit.setPlainText(''.join(ct_display))
#self.plainTextEdit.setPlainText(''.join(map(lambda x: x if x in string.printable else chr(21), map(chr, ct))))
self.connect(self.plainTextEdit, SIGNAL('cursorPositionChanged()'), self.on_plainTextEdit_cursorPositionChanged)
app = QApplication(sys.argv)
app.setStyle("cleanlooks")
win = MainWindow()
win.show()
sys.exit(app.exec_())
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'window.ui'
#
# Created: Wed Sep 27 12:47:57 2017
# by: PyQt4 UI code generator 4.10.1
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(815, 502)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.horizontalLayout_2 = QtGui.QHBoxLayout(self.centralwidget)
self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.plainTextEdit = QtGui.QPlainTextEdit(self.centralwidget)
font = QtGui.QFont()
font.setFamily(_fromUtf8("Inconsolata"))
font.setPointSize(12)
self.plainTextEdit.setFont(font)
self.plainTextEdit.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
self.plainTextEdit.setUndoRedoEnabled(False)
self.plainTextEdit.setLineWrapMode(QtGui.QPlainTextEdit.NoWrap)
self.plainTextEdit.setPlainText(_fromUtf8(""))
self.plainTextEdit.setObjectName(_fromUtf8("plainTextEdit"))
self.verticalLayout.addWidget(self.plainTextEdit)
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.label_4 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(12)
self.label_4.setFont(font)
self.label_4.setObjectName(_fromUtf8("label_4"))
self.horizontalLayout.addWidget(self.label_4)
self.spinBox_2 = QtGui.QSpinBox(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(12)
self.spinBox_2.setFont(font)
self.spinBox_2.setMaximum(500)
self.spinBox_2.setObjectName(_fromUtf8("spinBox_2"))
self.horizontalLayout.addWidget(self.spinBox_2)
self.label_3 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(12)
self.label_3.setFont(font)
self.label_3.setObjectName(_fromUtf8("label_3"))
self.horizontalLayout.addWidget(self.label_3)
self.spinBox_3 = QtGui.QSpinBox(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(12)
self.spinBox_3.setFont(font)
self.spinBox_3.setMaximum(3000)
self.spinBox_3.setObjectName(_fromUtf8("spinBox_3"))
self.horizontalLayout.addWidget(self.spinBox_3)
self.label = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(12)
self.label.setFont(font)
self.label.setObjectName(_fromUtf8("label"))
self.horizontalLayout.addWidget(self.label)
self.spinBox = QtGui.QSpinBox(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(12)
self.spinBox.setFont(font)
self.spinBox.setReadOnly(True)
self.spinBox.setMaximum(63)
self.spinBox.setObjectName(_fromUtf8("spinBox"))
self.horizontalLayout.addWidget(self.spinBox)
self.label_2 = QtGui.QLabel(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(12)
self.label_2.setFont(font)
self.label_2.setObjectName(_fromUtf8("label_2"))
self.horizontalLayout.addWidget(self.label_2)
self.lineEdit = QtGui.QLineEdit(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(12)
self.lineEdit.setFont(font)
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
self.horizontalLayout.addWidget(self.lineEdit)
self.pushButton = QtGui.QPushButton(self.centralwidget)
font = QtGui.QFont()
font.setPointSize(12)
self.pushButton.setFont(font)
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.horizontalLayout.addWidget(self.pushButton)
self.verticalLayout.addLayout(self.horizontalLayout)
self.horizontalLayout_2.addLayout(self.verticalLayout)
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(_translate("MainWindow", "o__o", None))
self.label_4.setText(_translate("MainWindow", "Line no:", None))
self.label_3.setText(_translate("MainWindow", "Actual offset:", None))
self.label.setText(_translate("MainWindow", "Modded offset", None))
self.label_2.setText(_translate("MainWindow", "Character:", None))
self.pushButton.setText(_translate("MainWindow", "Set", None))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment