Example #1
0
 def run(self):
     if (self.algorithm == 'RSA'):
         t = xRsa()
         print("Running RSA Decryption")
         #cipher = raw_input("Cipher text: ")
         plaintext = t.decrptyMsg(14638872678012233450065572822)
         # Print the string content after encryption and decryption
         print("decrypted text:" + plaintext)
     elif (self.algorithm == 'MD5'):
         print("unsupported")
     elif (self.algorithm == 'DES'):
         print("Running DES Decryption")
         desObj = des()
         desObj.decryption(
             "key.txt", "file(txt).des"
         )  # thie will generate file.txt at the same directory
     elif (self.algorithm == 'VG'):
         print("Running VG Decryption")
         obj = VG()
         cipher_text = input("Cipher_text: ")
         key = input("Key: ")
         obj.create_table(key)
         deciper_text = obj.decipher(cipher_text, key)
         print(deciper_text)
     else:
         print("end")
 def calculate(self):
     algo = VG()
     cipher_text = self.ids.cipher.text
     key = self.ids.key.text
     if (key != ''):
         algo.create_table(key)
         plane_text = algo.decipher(cipher_text, key)
         self.ids.plane.text = plane_text
     else:
         self.ids.cipher.text = cipher_text
Example #3
0
 def run(self):
     if (self.algorithm == 'RSA'):
         print("Running RSA Encrption")
         msg = raw_input('Message: ')
         t = xRsa()
         print("plain text:" + msg)
         cipher = t.encrptyMsg(msg)
         print("cipher text:" + str(cipher))
     elif (self.algorithm == 'MD5'):
         print("Running MD5 Encrption")
         key = input("key:")
         obj = MD5_State()
         buff = [''] * 16
         ciper = obj.md5_digest(key, len(key), buff)
         print("deciper_text =")
         for i in range(16):
             print("%x" % ((ord(buff[i]) & 0xF0) >> 4), end='')
             print("%x" % (ord(buff[i]) & 0x0F), end='')
         #encryption = MD5()
     elif (self.algorithm == 'DES'):
         print("Running DES Encrption")
         desObj = des()
         desObj.encryption(
             "key.txt", "file.txt"
         )  # this will generte file(des).txt at the same directory
     elif (self.algorithm == 'VG'):
         print("Running VG Encrption")
         key = raw_input('key:')
         input_string = raw_input('input_string:')
         obj = VG()
         obj.create_table(key)
         print('key')
         print(obj.dict_key)
         print(obj.dict_char2int)
         print(obj.dict_int2char)
         print(obj.table)
         ciper_text = obj.cipher(input_string, key)
         print(ciper_text)
     else:
         print('END')
Example #4
0
nu = par.nu

# changing parameterization from {theta,sigma, nu} to {c,m,g}
[c, m, g] = ParamChangeVG(theta, sigma, nu)
# -

# ## Initialize projection variables

tau = 10  # investment horizon
dt = 1 / 20  # infinitesimal step for simulations
t_j = arange(0,tau+dt,dt)  # time vector for simulations
j_ = 15  # number of simulations

# ## Simulate VG paths

x_j = VG(theta, sigma, nu, t_j, j_)[0]  # VG paths
x_j = x_j + tile(shift*t_j[newaxis,...],(j_, 1))  # shifted-VG path
x_j = pnl[t_-1] + x_j  # centered path

# ## Projection to horizon

# +
# moments
mu_tau, sigma2_tau, _, _ = ShiftedVGMoments(0, theta, sigma, nu, tau)
expectation = pnl[t_-1] + shift*tau + mu_tau  # shift and center mean
sigma_tau = sqrt(sigma2_tau)

# analytical pdf
l_ = 2000
par1 = namedtuple('par', 'c m g')
par1.c = c
Example #5
0
be = 0
de = 1
# convert parameters to Cont-Tankov notation
th, k, s = Schout2ConTank(al, be, de)

x_nig = NIG(th, k, s, t, j_)
# -

# ## Simulate Variance-Gamma process

# +
mu = 0.1  # deterministic drift in subordinated Brownian motion
kappa = 1
sigma = 0.2  # s.dev in subordinated Brownian motion

x_vg, _ = VG(mu, sigma, kappa, t, j_)
# -

# ## Generate figure

# +
t = t.reshape(1, -1)
f, ax = subplots(2, 1)
ax[0].plot(t.T, x_nig.T)
title('normal-inverse-Gaussian')

ax[1].plot(t.T, x_vg.T)
title('variance gamma')
plt.tight_layout()
# save_plot(ax=plt.gca(), extension='png', scriptname=os.path.basename('.')[:-3], count=plt.get_fignums()[-1])
Example #6
0
nu = par.nu

# #changing parameterization from {theta,sigma, nu} to {c,m,g}
# [c, m, g] = ParamChangeVG(theta,sigma,nu)
# -

# ## Initialize projection variables
tau = 15  # investment horizon
dt = 1 / 75  # infinitesimal step for simulations
t_j = arange(0, tau + dt, dt)  # time vector for simulations
j_ = 2  # number of simulations

# +
# ## Simulate VG paths

[X, T] = VG(theta, sigma, nu, t_j, j_)  # VG paths
X = X + tile(shift * t_j[newaxis, ...], (j_, 1))  # shifted-VG path
X = pnl[t_ - 1] + X  # centered path
dT = r_['-1', zeros((j_, 1)), diff(T, 1, 1)]
# -

# ## Projection to horizon

# moments
mu_tau, sigma2_tau, _, _ = ShiftedVGMoments(0, theta, sigma, nu, tau)
expectation = pnl[t_ - 1] + shift * tau + mu_tau  # shift and center mean
sigma_tau = sqrt(sigma2_tau)

# ## Generate the figure
s_ = 2
Example #7
0
from RSA import xRsa
from des import des
from md5 import MD5_State
import string
import sys

from pip._vendor.distlib.compat import raw_input

while True:
    input = raw_input('exit or work:')
    if input == 'exit':
        exit()
    elif input == 'work':
        type = raw_input("Select method(vg,des,rsa,md5):")
        if type == 'vg':
            vg_1 = VG()
            key = raw_input('key:')
            plain_text = raw_input('plain_text:')
            table = vg_1.create_table(key)
            print("Table created!")
            print(table)
            cipher_text = vg_1.cipher(plain_text, key)
            print("Encrypted finish")
            print(cipher_text)
            decrypt = raw_input("decript yes or no:")
            if decrypt == "yes":
                vg_1.decipher(cipher_text, key)
                decrypt_text = vg_1.decipher(cipher_text, key)
                print("Decrypted finished!")
                print(decrypt_text)
                continue