コード例 #1
0
    def __get_right_message(self, right_message, key):
        e_block = self.__apply_permutation(-1, right_message, 'E')

        binary = self.__build_binary(long(e_block, 2), long(key, 2))

        binary_array = self.__binary_to_array(binary)

        substitution_matrices = self.__init_substitution_matrices(binary_array)

        merged_substitution_matrices = self.__merge__substitution_matrices(
            substitution_matrices)

        return self.__apply_permutation(-1, merged_substitution_matrices,
                                        'PERM')
コード例 #2
0
 def __apply_permutation(self, i, merged_key, constant):
     block = ""
     for j in range(len(self.constants_by_key[constant])):
         block += merged_key[self.constants_by_key[constant][j] - 1]
     if 'CP_2' == constant:
         self.key[i] = long(block, 2)
     return block
コード例 #3
0
    def __build_parameterized_key(self, key):
        # Permit to convert long key to a binary
        binary_key = self.__long_to_binary(key)

        while len(binary_key) < 64:
            binary_key = "0" + binary_key

        pc1_binary_key = self.__apply_permutation(-1, binary_key, 'CP_1')

        left_integer = int(pc1_binary_key[0:28], 2)
        right_integer = int(pc1_binary_key[28:], 2)

        # Build the keys
        for i in range(1, len(self.key)):
            left_integer = self.__rotate_left(left_integer, self.shift_keys[i])
            right_integer = self.__rotate_left(right_integer,
                                               self.shift_keys[i])

            merged_halves = long(left_integer << 28) + right_integer
            merged_key = self.__long_to_binary(merged_halves)

            # if we see that leading zeros absent
            while len(merged_key) < 56:
                merged_key = "0" + merged_key

            # We apply permuted key for 56 bits
            self.__apply_permutation(i, merged_key, 'CP_2')
コード例 #4
0
    def __permute_messages(self, cipher, i, left_message, right_message):
        if Constantes.CIPHER == cipher:
            current_key = self.__long_to_binary(self.key[i + 1])
        else:
            current_key = self.__long_to_binary(self.key[i])

        while len(current_key) < 48:
            current_key = "0" + current_key

        binary_right_message = self.__get_right_message(
            right_message, current_key)

        merged_message = self.__long_to_binary(
            long(left_message, 2) ^ long(binary_right_message, 2))

        while len(merged_message) < 32:
            merged_message = "0" + merged_message
        left_message = right_message
        right_message = merged_message

        return left_message, right_message
コード例 #5
0
def main():
    a = 0
    b = 1
    tmp = cmp(a, b)
    print("tmp = ", tmp)  #前者小 -1,反之 1,== 0
    print(str(a))
    print(type(a))
    print(bool(a))
    print(int(a))
    print(long(a))
    print(float(a))
    print(complex(a))
    return
コード例 #6
0
ファイル: forms.py プロジェクト: lijoev/KCC
    def clean_phoneNumber(self):
        participant_phone = self.cleaned_data.get('phoneNumber', None)
        try:
            if long(participant_phone) and not participant_phone.isalpha():
                min_length = 10
                max_length = 13
                ph_length = str(participant_phone)
                if len(ph_length) < min_length or len(ph_length) > max_length:
                    raise ValidationError('Phone number length not valid')

        except (ValueError, TypeError):
            raise ValidationError('Please enter a valid phone number')
        return participant_phone
コード例 #7
0
ファイル: forms.py プロジェクト: lijoev/KCC
    def clean_responsible_person_contact(self):
        responsible_person_contact = self.cleaned_data.get(
            'responsible_person_contact', None)
        try:
            if long(responsible_person_contact
                    ) and not responsible_person_contact.isalpha():
                min_length = 10
                max_length = 13
                ph_length = str(responsible_person_contact)
                if len(ph_length) < min_length or len(ph_length) > max_length:
                    raise ValidationError('Phone number length not valid')

        except (ValueError, TypeError):
            raise ValidationError('Please enter a valid phone number')
        return responsible_person_contact
コード例 #8
0
def powerDigitalSum(n):
    number = str(long(math.pow(2, n)))
    return reduce(lambda x, y: int(x) + int(y), number)
コード例 #9
0
def largeSum(num):
    listOf50 = []
    for i in xrange(50, len(str(num))+1,50):
        listOf50.append(long(str(num)[i-50:i]))
    totalSum = reduce(lambda x , y : x + y, listOf50)
    return int(str(totalSum)[0:10])
コード例 #10
0
ファイル: Numbers.py プロジェクト: akshay1732/Python
@author: 10644845
'''
import math
from pip._vendor.pytoml.writer import long
from math import ceil, pi
import random
from random import choice, randrange, uniform, shuffle

a = int(15.9)
print(a)

b = float(45)
print(b)

c = long(2)
print(c)

d = complex(45, 2)
print(d)

a = -10.823
print("\n")
print(abs(a))
print(math.fabs(a))
print(ceil(a))
print(math.floor(a))
print(math.modf(a))
print(round(a, 1))
'''        *********************Random Number Functions    ********************'''