コード例 #1
0
ファイル: ED_test.py プロジェクト: MaxsLi/Encrypter
def test_number():
    """
    Test 16 random generated numbers, each number in range (-x^128, x^128).
    """
    for x in range(16):
        random_number: str = str(random.randint(-(x**128), x**128))
        encrypted_result: str = ED.encrypt(random_number)
        decrypted_result: str = ED.decrypt(encrypted_result)
        assert random_number == decrypted_result
コード例 #2
0
ファイル: jDBF.py プロジェクト: juckar/extenmgd
 def __init__( self, nomFichero ) :
     self.cFichero = nomFichero
     try:
         self.f = open(nomFichero, "rb")
     except:
         import ED
         ED.mensaje( "No se puede abrir el fichero de datos : %s"%self.cFichero )
         sys.exit(0)
     self._LeeCabecera()
コード例 #3
0
ファイル: ED_test.py プロジェクト: MaxsLi/Encrypter
def test_error_input():
    """
    Test 100 random generated string consist of special characters, letters and digits,
    Of length in range 1 to x. As input to the decrypt function, which should fail.
    """
    for x in range(2, 100):
        mixed_input: str = string.ascii_letters + string.digits + string.punctuation
        random_input: str = "".join(
            random.choice(mixed_input) for i in range(random.randint(1, x)))
        with pytest.raises(SyntaxError):
            ED.decrypt(random_input)
コード例 #4
0
ファイル: ED_test.py プロジェクト: MaxsLi/Encrypter
def test_character():
    """
    Test 16 random generated special characters, length of each character is in range (1, x^4).
    """
    for x in range(2, 16):
        characters: str = string.punctuation
        random_character: str = "".join(
            random.choice(characters) for i in range(random.randint(1, x**4)))
        encrypted_result: str = ED.encrypt(random_character)
        decrypted_result: str = ED.decrypt(encrypted_result)
        assert random_character == decrypted_result
コード例 #5
0
ファイル: ED_test.py プロジェクト: MaxsLi/Encrypter
def test_string():
    """
    Test 16 random generated letters, length of each letter is in range (1, x^4).
    """
    for x in range(2, 16):
        letters: str = string.ascii_letters
        random_letters: str = "".join(
            random.choice(letters) for i in range(random.randint(1, x**4)))
        encrypted_result: str = ED.encrypt(random_letters)
        decrypted_result: str = ED.decrypt(encrypted_result)
        assert random_letters == decrypted_result
コード例 #6
0
ファイル: ED_test.py プロジェクト: MaxsLi/Encrypter
def test_characters_letters_numbers():
    """
    Test 16 random generated string consist of special characters, letters and digits,
    Of length in range 1 to x^4.
    """
    for x in range(2, 16):
        mixed_input: str = string.ascii_letters + string.digits + string.punctuation
        random_input: str = "".join(
            random.choice(mixed_input) for i in range(random.randint(1, x**4)))
        encrypted_result: str = ED.encrypt(random_input)
        decrypted_result: str = ED.decrypt(encrypted_result)
        assert random_input == decrypted_result
コード例 #7
0
ファイル: main.py プロジェクト: 1nf1corp/Ebear-Bot
def on_message(ws, message):
    message = json.loads(message)
    for i in message:
        unicodedata.normalize('NFKD', i).encode('ascii', 'ignore')
    if message['cmd'] == 'chat':
        if message['text'].lower() == '|ebear' or message['text'].lower() == '|eb':
            _thread.start_new_thread(run, ())
        if message['text'].lower() == '|ebear -s' or message['text'].lower() == '|eb -s':
            _thread.start_new_thread(run, ((1,)))
        elif message['text'].lower() == '|source':
            ws.send(json.dumps({"cmd": "chat", "text": ("%s") % comm['|source']}))
        elif message['text'].lower() == '|help' or message['text'].lower() == '|h':
            ws.send(json.dumps({"cmd": "chat", "text": ("%s") % comm['|help']}))
        elif message['text'].lower()[:3] == '|g ':
            if len(message['text']) > 3:
                ws.send(json.dumps({"cmd": "chat", "text": google.search(message['text'][3:])}))
            else:
                ws.send(json.dumps({"cmd": "chat", "text": "Usage is |g \"string\""}))
        elif message['text'].lower() == '|g':
            ws.send(json.dumps({"cmd": "chat", "text": "Usage is |g \"string\""}))
        elif message['text'].lower()[:4] == '|ed ':
            if len(message['text']) > 4:
                ws.send(json.dumps({"cmd": "chat", "text": ED.search(message['text'][4:])}))
            else:
                ws.send(json.dumps({"cmd": "chat", "text": "Usage is |ed \"string\""}))
        elif message['text'].lower() == '|ed':
            ws.send(json.dumps({"cmd": "chat", "text": "Usage is |ed \"string\""}))
        afk(message)
コード例 #8
0
def data():
    #file=open("/home/vinoth/Desktop/task/simple_db_data.txt","r")
    file = open("/var/www/tas/simple_db_data.txt", "r")
    simple_db_data = file.read()
    simple_db_data = eval(simple_db_data + '}')
    file.close()

    #file=open("/home/vinoth/Desktop/task/hash.txt","r")
    file = open("var/www/tas/hash.txt", "r")
    hash_ = file.read()
    hash_ = eval(hash_ + '}')
    file.close()

    #file=open("/home/vinoth/Desktop/task/block_genesis_serialized.txt","r")
    file = open("/var/www/tas/block_genesis_serialized.txt", "r")
    block_genesis_serialized = file.read()
    block_genesis_serialized = eval(block_genesis_serialized + '}')
    file.close()

    simple_db_data = enc_dec.decrypt_all(simple_db_data)
    data = simple_db_data
    return render_template("index.html",
                           data=data,
                           h=hash_,
                           r=block_genesis_serialized)
コード例 #9
0
def create_form():
    id = request.form['id']
    name = enc_dec.encrypt_3des(request.form['name'])
    dob = enc_dec.encrypt_3des(request.form['dob'])
    email = enc_dec.encrypt_3des(request.form['email'])
    ph = enc_dec.encrypt_3des(request.form["ph"])

    file_ = request.files['file']
    #file_.save("/home/vinoth/Desktop/task/cv/"+str(id)+".pdf")
    #file=open("/home/vinoth/Desktop/task/simple_db_data.txt","a")
    file_.save("var/www/tas/cv/" + str(id) + ".pdf")
    file = open("/var/www/tas/simple_db_data.txt", "a")
    file.write("'" + str(id) + "'" + ":" + str({
        "name": name,
        "dob": dob,
        "email": email,
        "ph": ph
    }) + ",")
    file.close()

    fun(id, name, dob, email, ph)
    flash('User added successfully!')

    return redirect("/")
コード例 #10
0
ファイル: app.py プロジェクト: MaxsLi/Encrypter-Web-old
def decrypt():
    """
    Decrypt the Given cypher using Encrypter
    """
    try:
        return render_template('response.html',
                               version=ED.__version__,
                               dark_theme=session['dark_theme'],
                               input=request.form['input'],
                               message="Decrypted",
                               response=ED.decrypt(request.form['input']))
    except SyntaxError as error:
        return render_template('response.html',
                               version=ED.__version__,
                               dark_theme=session['dark_theme'],
                               input=request.form['input'],
                               message="Error",
                               response=error.msg)
コード例 #11
0
chi_max = args.chi_max      ## maxmum bond dimension at truncation


print("2S = m - 1, N-site spin chain")
print("N = "+repr(N))
print("m = "+repr(m))
print("Hamiltonian parameters:")
print("Jz = "+repr(Jz))
print("Jxy = "+repr(Jxy))
print("hx = "+repr(hx))
print("D = "+repr(D))



## Obtain the smallest eigenvalue
eig_val,eig_vec = ED.Calc_GS(m,Jz, Jxy,hx,D,N,k=1)
print("Ground state energy per bond= " +repr(eig_val[0]/(N-1)))



## Make exact MPS (from "left")
Tn = []
lam = [np.ones((1,))]
lam_inv = 1.0/lam[0]
R_mat = eig_vec[:,0].reshape(m,m**(N-1))

chi_l=1
for i in range(N-1):
    U,s,VT = linalg.svd(R_mat,full_matrices=False)
    chi_r = s.size
コード例 #12
0
ファイル: ED_test.py プロジェクト: MaxsLi/Encrypter
def test_empty_input():
    """
    Test empty input on encrypt function, which return an error message.
    """
    with pytest.raises(SyntaxError):
        ED.encrypt('')
コード例 #13
0
ファイル: main.py プロジェクト: paradoxnafi/EbearBot
def cmndBlk(msg):
    if msg['cmd'] == 'chat':
        if msg['text'].lower().strip() == '|eb':
            _thread.start_new_thread(runBear, (0, ))
        elif msg['text'].lower().strip() == '|eb -s':
            _thread.start_new_thread(runBear, (1, ))
        elif msg['text'].lower()[:9] == '|eb -say ' and len(msg['text']) > 9:
            _thread.start_new_thread(runBear, ((2, msg['text'][9:]), ))
        elif msg['text'].lower().strip() == '|source':
            ws.send(
                json.dumps({
                    'cmd': 'chat',
                    'text': ('%s') % comm['|source']
                }))
        elif (msg['text'].lower().strip() == '|help'
              or msg['text'].lower().strip() == '|h'):
            ws.send(json.dumps({
                'cmd': 'chat',
                'text': ('%s') % comm['|help']
            }))
        elif msg['text'].lower()[:3] == '|g ':
            if len(msg['text'].strip()) > 3:
                ws.send(
                    json.dumps({
                        'cmd': 'chat',
                        'text': Google.search(msg['text'][3:])
                    }))
            else:
                ws.send(
                    json.dumps({
                        'cmd': 'chat',
                        'text': 'Usage is |g \"string\"'
                    }))
        elif msg['text'].lower()[:4] == '|ed ':
            if len(msg['text']) > 4:
                ws.send(
                    json.dumps({
                        'cmd': 'chat',
                        'text': ED.search(msg['text'][4:])
                    }))
            else:
                ws.send(
                    json.dumps({
                        'cmd': 'chat',
                        'text': 'Usage is |ed \"string\"'
                    }))
        elif msg['text'].lower() == '|ed':
            ws.send(
                json.dumps({
                    'cmd': 'chat',
                    'text': 'Usage is |ed \"string\"'
                }))
        elif msg['text'].lower()[:4] == '|wa ':
            if len(msg['text']) > 4:
                ws.send(
                    json.dumps({
                        'cmd': 'chat',
                        'text': WA.search(msg['text'][4:])
                    }))
            else:
                ws.send(
                    json.dumps({
                        'cmd': 'chat',
                        'text': 'Usage is |wa \"string\"'
                    }))
        elif msg['text'].lower() == '|wa':
            ws.send(
                json.dumps({
                    'cmd': 'chat',
                    'text': 'Usage is |wa \"string\"'
                }))
        elif msg['text'].lower() == '|uptime':
            ws.send(
                json.dumps({
                    'cmd': 'chat',
                    'text': '%s' % prsDrtn(time.time() - joined)
                }))
        afk(msg)
        responses(msg)
コード例 #14
0
hx = args.hx  ## external field along x direction
D = args.D  ## single ion anisotropy
periodic = args.periodic  ## periodic boundasry condition

print("2S = m - 1, N-site spin chain")
print("N = " + repr(N))
print("m = " + repr(m))
print("Hamiltonian parameters:")
print("Jz = " + repr(Jz))
print("Jxy = " + repr(Jxy))
print("hx = " + repr(hx))
print("D = " + repr(D))
print("periodic = " + repr(periodic))

## Obtain the smallest eigenvalue
eig_val, eig_vec = ED.Calc_GS(m, Jz, Jxy, hx, D, N, k=1, periodic=periodic)
if periodic:
    print("Ground state energy per bond= " + repr(eig_val[0] / N))
else:
    print("Ground state energy per bond= " + repr(eig_val[0] / (N - 1)))

## Make matrix from wave function
Mat = eig_vec[:, 0].reshape(m**int(N / 2), m**(N - int(N / 2)))

## SVD
U, s, VT = linalg.svd(Mat, full_matrices=False)

## Entanglement entropy
EE = -np.sum(s**2 * np.log(s**2))
print("normalization = " + repr(np.sum(s**2)))
コード例 #15
0
from cjm import *
コード例 #16
0
import ED
from scipy.sparse.linalg import eigs, eigsh

#Example Case: Single Particle on a 2 X 2 square lattice

#Initialize Hamiltonian object with required parameters w.r.t the given order
# (M, N, T, U, lac(required only for 2D case) ) in which
# M = # of sites, N = # of particles, T = hopping strength, U = interaction strength
# lac = this parameter is only required when setting up 2D lattice in our case it is 2 since
# we are dealing with 2 X 2 square lattice amounting to 4 sites
H = ED.Hamiltonian(4, 1, 1, 1, 2)

#Forming interaction hamiltonian and hopping hamiltonian
H_int = H.H_int()
H_kin = H.H_kin(H.lattice2D(
))  #!!! In 1D case make sure to use lattice1D() function and leave empty the
# lac parameter above

H_tot = (H_int.tocsr() + H_kin.tocsr())

#One can compute the dimension of hilbert space so that the Lanczos can look for such number of eigenvalues
print(
    H.D()
)  #It will result in 4 in our case, we configured the functions below to look for 2 eigenvalues

#This method is more efficient for computing low lying eigenvalues :
eig_val, eig_vecs = eigs(
    H_tot, 2, sigma=-5
)  # Looking for 2 eigenvalues the arg < H.D() condition must be satisfied!

#More generic way w/o any specification of the spectrum