精华内容
下载资源
问答
  • to_number用法示例 Number()函数 (Number() function) Number() function is a predefined global function in JavaScript, it used to convert an object to the number. If the function is not able to convert ...

    to_number用法示例

    Number()函数 (Number() function)

    Number() function is a predefined global function in JavaScript, it used to convert an object to the number. If the function is not able to convert the object in a number – it returns "NaN". (Read more: NaN in JavaScript).

    Number()函数是JavaScript中预定义的全局函数,用于将对象转换为数字。 如果函数无法将对象转换为数字,则返回“ NaN” 。 (了解更多: JavaScript中的NaN )。

    Note:

    注意:

    • If we convert Boolean values to the number, Number() function returns 0 or 1.

      如果将布尔值转换为数字,则Number()函数将返回0或1。

    • If we convert a date object to the number, Number() function returns value in milliseconds.

      如果我们将日期对象转换为数字,则Number()函数将返回以毫秒为单位的值。

    Example:

    例:

    <html>
    <head>
    <title>JavaScipt Example</title>
    </head>
    
    <body>
    	<script>		
    		var a = "10";	
    		var b = "10 20";
    		var c = "1234 Hello";
    		var d = "Hello 1234";
    		var e = true;	
    		var f = new Date();
    		
    		//converting values to number using Number() function
    		document.write("Number(a) = " + Number(a) + "<br>");
    		document.write("Number(b) = " + Number(b) + "<br>");
    		document.write("Number(c) = " + Number(c) + "<br>");
    		document.write("Number(d) = " + Number(d) + "<br>");
    		document.write("Number(e) = " + Number(e) + "<br>");
    		document.write("Number(f) = " + Number(f) + "<br>");
    	</script>
    </body>
    </html>
    
    

    Output

    输出量

    Number(a) = 10
    Number(b) = NaN
    Number(c) = NaN
    Number(d) = NaN
    Number(e) = 1
    Number(f) = 1549128507537
    
    
    

    翻译自: https://www.includehelp.com/code-snippets/Number-function-with-example-in-javascript.aspx

    to_number用法示例

    展开全文
  • 本文整理汇总了Python中Crypto.Util.number.long_to_bytes方法的典型用法代码示例。如果您正苦于以下问题:Python number.long_to_bytes方法的具体用法?Python number.long_to_bytes怎么用?Python number.long_to_...

    本文整理汇总了Python中Crypto.Util.number.long_to_bytes方法的典型用法代码示例。如果您正苦于以下问题:Python number.long_to_bytes方法的具体用法?Python number.long_to_bytes怎么用?Python number.long_to_bytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块Crypto.Util.number的用法示例。

    在下文中一共展示了number.long_to_bytes方法的26个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

    示例1: generateQ

    ​点赞 6

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def generateQ(randfunc):

    S=randfunc(20)

    hash1=SHA.new(S).digest()

    hash2=SHA.new(long_to_bytes(bytes_to_long(S)+1)).digest()

    q = bignum(0)

    for i in range(0,20):

    c=bord(hash1[i])^bord(hash2[i])

    if i==0:

    c=c | 128

    if i==19:

    c= c | 1

    q=q*256+c

    while (not isPrime(q)):

    q=q+2

    if pow(2,159L) < q < pow(2,160L):

    return S, q

    raise RuntimeError('Bad q value generated')

    开发者ID:mortcanty,项目名称:earthengine,代码行数:19,

    示例2: change_key

    ​点赞 6

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def change_key(self, master_key):

    if master_key >= (1 << 128):

    raise InvalidInputException('Master key should be 128-bit')

    self.__master_key = long_to_bytes(master_key, 16)

    self.__aes_ecb = AES.new(self.__master_key, AES.MODE_ECB)

    self.__auth_key = bytes_to_long(self.__aes_ecb.encrypt(b'\x00' * 16))

    # precompute the table for multiplication in finite field

    table = [] # for 8-bit

    for i in range(16):

    row = []

    for j in range(256):

    row.append(self.gf_2_128_mul(self.__auth_key, j << (8 * i)))

    table.append(tuple(row))

    self.__pre_table = tuple(table)

    self.prev_init_value = None # reset

    开发者ID:bkerler,项目名称:edl,代码行数:20,

    示例3: decrypt

    ​点赞 6

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def decrypt(self, ciphertext: bytes) -> bytes:

    c = bytes_to_long(ciphertext)

    # compute c**d (mod n)

    if (hasattr(self.key, 'p') and hasattr(self.key, 'q') and hasattr(self.key, 'u')):

    m1 = pow(c, self.key.d % (self.key.p - 1), self.key.p)

    m2 = pow(c, self.key.d % (self.key.q - 1), self.key.q)

    h = m2 - m1

    if (h < 0):

    h = h + self.key.q

    h = h * self.key.u % self.key.q

    plaintext = h * self.key.p + m1

    else:

    plaintext = pow(c, self.key.d, self.key.n)

    return long_to_bytes(plaintext)

    开发者ID:GoSecure,项目名称:pyrdp,代码行数:20,

    示例4: writePublicKey

    ​点赞 6

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def writePublicKey(self, publicKey: RSA.RsaKey) -> bytes:

    modulus = publicKey.n

    publicExponent = publicKey.e

    # Modulus must be reversed because bytes_to_long expects it to be in big endian format

    modulusBytes = long_to_bytes(modulus)[:: -1]

    stream = BytesIO()

    stream.write(b"RSA1")

    Uint32LE.pack(len(modulusBytes) + 8, stream)

    Uint32LE.pack(2048, stream)

    Uint32LE.pack(255, stream)

    Uint32LE.pack(publicExponent, stream)

    stream.write(modulusBytes)

    stream.write(b"\x00" * 8)

    return stream.getvalue()

    开发者ID:GoSecure,项目名称:pyrdp,代码行数:18,

    示例5: derive_key

    ​点赞 6

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def derive_key(password):

    start = bytes_to_long(password)

    #Making sure I am safe from offline bruteforce attack

    for i in range(NB_ITERATIONS):

    start = start ** e

    start %= N

    #We are never too cautious let's make it harder

    key = 1

    for i in range(NB_ITERATIONS):

    key = key ** e

    key %= N

    key *= start

    key %= N

    return sha256(long_to_bytes(key)).digest()

    开发者ID:The-Art-of-Hacking,项目名称:h4cker,代码行数:21,

    示例6: pubKeyXML

    ​点赞 6

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def pubKeyXML(pemPublicKeyFile):

    with open (pemPublicKeyFile, 'rb') as pkFile:

    pemPublicKey = pkFile.read()

    publicKey = RSA.importKey(pemPublicKey)

    xml = ''

    xml += ''

    xml += standard_b64encode(number.long_to_bytes(publicKey.n))

    xml += ''

    xml += ''

    xml += standard_b64encode(number.long_to_bytes(publicKey.e))

    xml += ''

    xml += ''

    fileName = basename(pemPublicKeyFile)

    with open (fileName+'.xml', 'w') as pkFile:

    pkFile.write(xml)

    return

    #

    # CreateXMLPrivKey

    #

    开发者ID:MisterDaneel,项目名称:PemToXml,代码行数:21,

    示例7: _noise

    ​点赞 6

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def _noise(self):

    # Adds a bit of noise to the random pool, by adding in the

    # current time and CPU usage of this process.

    # The difference from the previous call to _noise() is taken

    # in an effort to estimate the entropy.

    t=time.time()

    delta = (t - self._lastcounter)/self._ticksize*1e6

    self._lastcounter = t

    self._addBytes(long_to_bytes(int(1000*time.time())))

    self._addBytes(long_to_bytes(int(1000*time.clock())))

    self._addBytes(long_to_bytes(int(1000*time.time())))

    self._addBytes(long_to_bytes(int(delta)))

    # Reduce delta to a maximum of 8 bits so we don't add too much

    # entropy as a result of this call.

    delta=delta % 0xff

    return int(delta)

    开发者ID:kuri65536,项目名称:python-for-android,代码行数:19,

    示例8: generateQ

    ​点赞 6

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def generateQ(randfunc):

    S=randfunc(20)

    hash1=SHA.new(S).digest()

    hash2=SHA.new(long_to_bytes(bytes_to_long(S)+1)).digest()

    q = bignum(0)

    for i in range(0,20):

    c=ord(hash1[i])^ord(hash2[i])

    if i==0:

    c=c | 128

    if i==19:

    c= c | 1

    q=q*256+c

    while (not isPrime(q)):

    q=q+2

    if pow(2,159) < q < pow(2,160):

    return S, q

    raise error('Bad q value generated')

    开发者ID:kuri65536,项目名称:python-for-android,代码行数:19,

    示例9: _noise

    ​点赞 6

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def _noise(self):

    # Adds a bit of noise to the random pool, by adding in the

    # current time and CPU usage of this process.

    # The difference from the previous call to _noise() is taken

    # in an effort to estimate the entropy.

    t=time.time()

    delta = (t - self._lastcounter)/self._ticksize*1e6

    self._lastcounter = t

    self._addBytes(long_to_bytes(long(1000*time.time())))

    self._addBytes(long_to_bytes(long(1000*time.clock())))

    self._addBytes(long_to_bytes(long(1000*time.time())))

    self._addBytes(long_to_bytes(long(delta)))

    # Reduce delta to a maximum of 8 bits so we don't add too much

    # entropy as a result of this call.

    delta=delta % 0xff

    return int(delta)

    开发者ID:kuri65536,项目名称:python-for-android,代码行数:19,

    示例10: generateQ

    ​点赞 6

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def generateQ(randfunc):

    S=randfunc(20)

    hash1=SHA.new(S).digest()

    hash2=SHA.new(long_to_bytes(bytes_to_long(S)+1)).digest()

    q = bignum(0)

    for i in range(0,20):

    c=ord(hash1[i])^ord(hash2[i])

    if i==0:

    c=c | 128

    if i==19:

    c= c | 1

    q=q*256+c

    while (not isPrime(q)):

    q=q+2

    if pow(2,159L) < q < pow(2,160L):

    return S, q

    raise error, 'Bad q value generated'

    开发者ID:kuri65536,项目名称:python-for-android,代码行数:19,

    示例11: pack

    ​点赞 6

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def pack(data):

    ret = ''

    for part in data:

    if type(part) in (type(()), type([])):

    partData = pack(part)

    partType = SEQUENCE|0x20

    elif type(part) in (type(1), type(1L)):

    partData = number.long_to_bytes(part)

    if ord(partData[0])&(0x80):

    partData = '\x00' + partData

    partType = INTEGER

    else:

    raise 'unknown type %s' % type(part)

    ret += chr(partType)

    if len(partData) > 127:

    l = number.long_to_bytes(len(partData))

    ret += chr(len(l)|0x80) + l

    else:

    ret += chr(len(partData))

    ret += partData

    return ret

    开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:24,

    示例12: monty_pow

    ​点赞 6

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def monty_pow(base, exp, modulus):

    max_len = len(long_to_bytes(max(base, exp, modulus)))

    base_b, exp_b, modulus_b = [ long_to_bytes(x, max_len) for x in

    (base, exp, modulus) ]

    out = create_string_buffer(max_len)

    error = _raw_montgomery.monty_pow(

    out,

    base_b,

    exp_b,

    modulus_b,

    c_size_t(max_len),

    c_ulonglong(32)

    )

    if error == 17:

    raise ExceptionModulus()

    if error:

    raise ValueError("monty_pow failed with error: %d" % error)

    result = bytes_to_long(get_raw_buffer(out))

    return result

    开发者ID:vcheckzen,项目名称:FODI,代码行数:25,

    示例13: _compute_mac

    ​点赞 6

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def _compute_mac(self):

    """Compute MAC without any FSM checks."""

    if self._tag:

    return self._tag

    # Step 5 in NIST SP 800-38D, Algorithm 4 - Compute S

    self._pad_cache_and_update()

    self._update(long_to_bytes(8 * self._auth_len, 8))

    self._update(long_to_bytes(8 * self._msg_len, 8))

    s_tag = self._signer.digest()

    # Step 6 - Compute T

    self._tag = self._tag_cipher.encrypt(s_tag)[:self._mac_len]

    return self._tag

    开发者ID:vcheckzen,项目名称:FODI,代码行数:18,

    示例14: _compute_mac

    ​点赞 6

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def _compute_mac(self):

    """Finalize the cipher (if not done already) and return the MAC."""

    if self._mac_tag:

    assert(self._status == _CipherStatus.PROCESSING_DONE)

    return self._mac_tag

    assert(self._status != _CipherStatus.PROCESSING_DONE)

    if self._status == _CipherStatus.PROCESSING_AUTH_DATA:

    self._pad_aad()

    if self._len_ct & 0x0F:

    self._authenticator.update(b'\x00' * (16 - (self._len_ct & 0x0F)))

    self._status = _CipherStatus.PROCESSING_DONE

    self._authenticator.update(long_to_bytes(self._len_aad, 8)[::-1])

    self._authenticator.update(long_to_bytes(self._len_ct, 8)[::-1])

    self._mac_tag = self._authenticator.digest()

    return self._mac_tag

    开发者ID:vcheckzen,项目名称:FODI,代码行数:23,

    示例15: generate_RSA

    ​点赞 6

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def generate_RSA(pridir, pubdir):

    key = RSA.generate(2048)

    with open(pridir, 'wb') as content_file:

    content_file.write(key.exportKey('PEM'))

    print("Private key written to home directory " + pridir)

    with open(pubdir, 'wb') as content_file:

    # Ugly hack to introduce pycrypto v2.7a1

    # Original: .exportKey('OpenSSH')

    eb = long_to_bytes(key.e)

    nb = long_to_bytes(key.n)

    if bord(eb[0]) & 0x80:

    eb = bchr(0x00) + eb

    if bord(nb[0]) & 0x80:

    nb = bchr(0x00) + nb

    keyparts = [b('ssh-rsa'), eb, nb]

    keystring = b('').join(

    [struct.pack(">I", len(kp)) + kp for kp in keyparts])

    content_file.write(b('ssh-rsa ') + binascii.b2a_base64(keystring)[:-1])

    print("Public key written to home directory " + pubdir)

    return sha1(key.exportKey('PEM')).hexdigest()

    开发者ID:projectarkc,项目名称:arkc-client,代码行数:22,

    示例16: export_privatekeyblob

    ​点赞 6

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def export_privatekeyblob(self):

    key = self.key.key

    n = key.n

    e = key.e

    d = key.d

    p = key.p

    q = key.q

    n_bytes = long_to_bytes(n)[::-1]

    key_len = len(n_bytes) * 8

    result = PUBLICKEYSTRUC_s.pack(bType_PRIVATEKEYBLOB, CUR_BLOB_VERSION, CALG_RSA_KEYX)

    result += RSAPUBKEY_s.pack(PRIVATEKEYBLOB_MAGIC, key_len, e)

    result += n_bytes

    result += long_to_bytes(p, key_len / 16)[::-1]

    result += long_to_bytes(q, key_len / 16)[::-1]

    result += long_to_bytes(d % (p - 1), key_len / 16)[::-1]

    result += long_to_bytes(d % (q - 1), key_len / 16)[::-1]

    result += long_to_bytes(inverse(q, p), key_len / 16)[::-1]

    result += long_to_bytes(d, key_len / 8)[::-1]

    return result

    开发者ID:crappycrypto,项目名称:wincrypto,代码行数:22,

    示例17: extractSecretKey

    ​点赞 5

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def extractSecretKey(self, globalSalt, masterPassword, entrySalt):

    (globalSalt, masterPassword, entrySalt) = self.is_masterpassword_correct(masterPassword)

    if unhexlify('f8000000000000000000000000000001') not in self.key3:

    return None

    privKeyEntry = self.key3[unhexlify('f8000000000000000000000000000001')]

    saltLen = ord(privKeyEntry[1])

    nameLen = ord(privKeyEntry[2])

    privKeyEntryASN1 = decoder.decode(privKeyEntry[3 + saltLen + nameLen:])

    data = privKeyEntry[3 + saltLen + nameLen:]

    self.printASN1(data, len(data), 0)

    # see https://github.com/philsmd/pswRecovery4Moz/blob/master/pswRecovery4Moz.txt

    entrySalt = privKeyEntryASN1[0][0][1][0].asOctets()

    privKeyData = privKeyEntryASN1[0][1].asOctets()

    privKey = self.decrypt3DES(globalSalt, masterPassword, entrySalt, privKeyData)

    self.printASN1(privKey, len(privKey), 0)

    privKeyASN1 = decoder.decode(privKey)

    prKey = privKeyASN1[0][2].asOctets()

    self.printASN1(prKey, len(prKey), 0)

    prKeyASN1 = decoder.decode(prKey)

    id = prKeyASN1[0][1]

    key = long_to_bytes(prKeyASN1[0][3])

    return key

    # --------------------------------------------

    # Get the path list of the firefox profiles

    开发者ID:mehulj94,项目名称:Radium,代码行数:33,

    示例18: _shift_bytes

    ​点赞 5

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def _shift_bytes(bs, xor_lsb=0):

    num = (bytes_to_long(bs)<<1) ^ xor_lsb

    return long_to_bytes(num, len(bs))[-len(bs):]

    开发者ID:mortcanty,项目名称:earthengine,代码行数:5,

    示例19: _lengthOctets

    ​点赞 5

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def _lengthOctets(self, payloadLen):

    """Return a byte string that encodes the given payload length (in

    bytes) in a format suitable for a DER length tag (L).

    """

    if payloadLen>127:

    encoding = long_to_bytes(payloadLen)

    return bchr(len(encoding)+128) + encoding

    return bchr(payloadLen)

    开发者ID:mortcanty,项目名称:earthengine,代码行数:10,

    示例20: encode

    ​点赞 5

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def encode(self):

    """Return a complete INTEGER DER element, fully encoded as a TLV."""

    self.payload = long_to_bytes(self.value)

    if bord(self.payload[0])>127:

    self.payload = bchr(0x00) + self.payload

    return DerObject.encode(self)

    开发者ID:mortcanty,项目名称:earthengine,代码行数:8,

    示例21: decryptKey

    ​点赞 5

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def decryptKey(encryptedKey):

    """Decrypts an RSA-encrypted key"""

    rsa = RSA.construct((long(constants.rsaModulus), long(constants.rsaExponent)))

    try:

    return rsa.encrypt(encryptedKey, 0)[0]

    except NotImplementedError:

    # pycryptodome

    return long_to_bytes(rsa._encrypt(bytes_to_long(encryptedKey)))

    开发者ID:ma1co,项目名称:Sony-PMCA-RE,代码行数:10,

    示例22: MGF1

    ​点赞 5

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def MGF1(mgfSeed, maskLen, hash):

    """Mask Generation Function, described in B.2.1"""

    T = b("")

    for counter in xrange(ceil_div(maskLen, hash.digest_size)):

    c = long_to_bytes(counter, 4)

    T = T + hash.new(mgfSeed + c).digest()

    assert(len(T)>=maskLen)

    return T[:maskLen]

    开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,

    示例23: lsbitoracle

    ​点赞 5

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def lsbitoracle(flag_enc, _decrypt, e, N, upper_limit, lower_limit):

    """

    Reference: https://crypto.stackexchange.com/questions/11053/rsa-least-significant-bit-oracle-attack

    Function implementing LSBit Oracle Attack

    *Warning*: Function does not return the last byte of the final plaintext

    :parameters:

    flag_enc : str

    Ciphertext you want to decrypt

    _decrypt : function

    Function interacting with the server for decryption

    e : int/long

    Public Key exponent

    N : long

    Public Key Modulus

    upper_limit: long

    Maximum value of corresponding plaintext of flag_enc

    lower_limit: long

    Minimum value of corresponding plaintext of flag_enc

    Since the attack messes up with the last byte of the plaintext, lsbitoracle

    function returns only flag[:-1]. It returns -1 in case of any Exception

    """

    flag = ""

    i = 1

    while lower_limit < upper_limit:

    chosen_ct = long_to_bytes((bytes_to_long(flag_enc)*pow(2**i, e, N)) % N)

    output = _decrypt(chosen_ct)

    if ord(output[-1]) == 0:

    upper_limit = (upper_limit + lower_limit)/2

    elif ord(output[-1]) == 1:

    lower_limit = (lower_limit + upper_limit)/2

    else:

    return -1

    i += 1

    # clearing the last byte from the flag

    flag = lower_limit & (~0xff)

    return long_to_bytes(flag)

    开发者ID:ashutosh1206,项目名称:Crypton,代码行数:42,

    示例24: hastad_unpadded

    ​点赞 5

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def hastad_unpadded(ct_list, mod_list, e):

    """

    Implementing Hastad's Broadcast Attack

    """

    m_expo = crt(ct_list, mod_list)

    if m_expo != -1:

    eth_root = gmpy2.iroot(m_expo, e)

    if eth_root[1] == False:

    print "[+] Cannot calculate e'th root!"

    return -1

    elif eth_root[1] == True:

    return long_to_bytes(eth_root)

    else:

    print "[+] Cannot calculate CRT"

    return -1

    开发者ID:ashutosh1206,项目名称:Crypton,代码行数:17,

    示例25: curve25519

    ​点赞 5

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def curve25519(secret, basepoint):

    a = ord(secret[0])

    a &= 248

    b = ord(secret[31])

    b &= 127

    b |= 64

    s = chr(a) + secret[1:-1] + chr(b)

    s = number.bytes_to_long(s[::-1])

    basepoint = number.bytes_to_long(basepoint[::-1])

    x, z = curve25519_mult(s, basepoint)

    zmone = number.inverse(z, CURVE_P)

    z = x * zmone % CURVE_P

    return number.long_to_bytes(z)[::-1]

    开发者ID:n0fate,项目名称:iChainbreaker,代码行数:17,

    示例26: pkcs_i2osp

    ​点赞 5

    # 需要导入模块: from Crypto.Util import number [as 别名]

    # 或者: from Crypto.Util.number import long_to_bytes [as 别名]

    def pkcs_i2osp(x,xLen):

    """

    Converts a long (the first parameter) to the associated byte string

    representation of length l (second parameter). Basically, the length

    parameters allow the function to perform the associated padding.

    Input : x nonnegative integer to be converted

    xLen intended length of the resulting octet string

    Output: x corresponding nonnegative integer

    Reverse function is pkcs_os2ip().

    """

    z = number.long_to_bytes(x)

    padlen = max(0, xLen-len(z))

    return '\x00'*padlen + z

    # for every hash function a tuple is provided, giving access to

    # - hash output length in byte

    # - associated hash function that take data to be hashed as parameter

    # XXX I do not provide update() at the moment.

    # - DER encoding of the leading bits of digestInfo (the hash value

    # will be concatenated to create the complete digestInfo).

    #

    # Notes:

    # - MD4 asn.1 value should be verified. Also, as stated in

    # PKCS#1 v2.1, MD4 should not be used.

    # - hashlib is available from http://code.krypto.org/python/hashlib/

    # - 'tls' one is the concatenation of both md5 and sha1 hashes used

    # by SSL/TLS when signing/verifying things

    开发者ID:theralfbrown,项目名称:smod-1,代码行数:32,

    注:本文中的Crypto.Util.number.long_to_bytes方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。

    展开全文
  • Oracle中to_number()函数的用法

    万次阅读 2017-03-02 15:30:13
    用cast就可,但要填适当的类型,示例:select cast(11 as unsigned int) /*整型*/select cast(11 as decimal(10,2)) /*浮点型*/ (1)将char或varchar2类型的string转换为一个number类型的...

    类似于mysql


    cast就可,但要填适当的类型,示例:

    select cast(11 as unsigned int) /*整型*/

    select cast(11 as decimal(10,2)) /*浮点型*/




    (1)将char或varchar2类型的string转换为一个number类型的数值,

    需要注意的是,被转换的字符串必须符合数值类型格式,如果被转换的

    字符串不符合数值型格式,Oracle将抛出错误提示;

    (2)to_number和to_char恰好是两个相反的函数; 

    to_number(varchar2 or char,'格式')

    [sql] view plain copy
     在CODE上查看代码片派生到我的代码片
    1. select to_number('000012134'from dual;  
    2. select to_number('88877'from dual;   

    (2)如果数字在格式范围内的话,就是正确的,否则就是错误的;如:

    [sql] view plain copy
     在CODE上查看代码片派生到我的代码片
    1. select to_number('$12345.678''$999999.99'from dual;  
    2. select to_number('$12345.678''$999999.999'from dual;  

    (3)可以用来实现进制转换;16进制转换为10进制:

    [sql] view plain copy
     在CODE上查看代码片派生到我的代码片
    1. select to_number('19f','xxx'from dual;  
    2. select to_number('f','xx'from dual;  

    1 用法简介

    TO_NUMBER函数()是Oracle中常用的类型转换函数之一,主要是将字符串转换为数值型的格式,与TO_CHAR()函数的作用正好相反。

    To_number函数的格式如下:

    To_number(varchar2 or char,’format model’)
    • 1
    • 1

    To_number函数中也有很多预定义的固定格式:

    格式值 含义
    9 代表一个数字
    0 强迫0显示
    $ 显示美元符号
    L 强制显示一个当地的货币符号
    . 显示一个小数点
    , 显示一个千位分隔符号

    2 一些例子

    SQL> select to_number(’RMB234234.4350′,’L999999.0000′) from dual;
        TO_NUMBER(’RMB234234.4350′,’L999999.0000′)
        ——————————————
        234234.435
    • 1
    • 2
    • 3
    • 4
    • 1
    • 2
    • 3
    • 4
    SQL> select to_number(’$123,233,455,623.3400′,’$999,999,999,999.0000′) from dual;
        TO_NUMBER(’$123,233,455,623.3400′,’$999,999,999,999.0000′)
        ———————————————————-
        1.2323E+11
    • 1
    • 2
    • 3
    • 4
    • 1
    • 2
    • 3
    • 4

    3 用法陷阱

    有的时候你会发现,使用了TO_NUMBER()函数并且语法正确,但是Oracle却报“invalid number”的错误,而你在一遍又一遍认认真真检查并确定语句无误之后大呼惊奇,以为TO_NUMBER()函数还有什么可能不知道的用法。其实这很可能是你所查询的数据出现了问题,而非SQL。使用TO_NUMBER()函数的时候,一定要确保所转换字段是可转换为数字的,比如字符串“20151008”是可以转换为数字20151008的,但是字符串“2015-10-08”不可以。如果你的字段中包含了字符串“2015-10-08”,而你还直接使用了TO_NUMBER()函数进行操作的话就会报“invalid number”的错。

    4 逃出陷阱

    如何逃出陷阱呢?

    1 前端校验

    尽量在用户输入的时候进行必要的校验,确保输入的数值就是我们需要的格式。

    2 后台校验

    在后台代码中进行必要的检查,筛选到错误的值并且传给前台合理的提示。

    3 SQL校验

    一旦你的数值进了数据库,问题就变得复杂了。还有一种情况是,数据是历史的,我们不能修改它,但是还要进行必要的查询。这时候就需要在SQL层面做点什么了。假设需要使用TO_NUMBER()函数的字段是varchar2类型的名为“status”。比如,如果非法数据都是比较长的,你可以在SQL中加上长度的校验,即多加一个where条件:

    LENGTH(status) <= 10
    • 1
    • 1

    或者,也可以将非法字符替换掉,,同样是在where中多加一个条件:

    TO_NUMBER(REGEXP_REPLACE(status,'[^0-9]','')) > 30
    • 1
    • 1

    实例中REGEXP_REPLACE()将“status”字段中所有非数字的字符替换为空字符,然后再用TO_NUMBER()进行比较就可以啦!




    展开全文
  • Here is something I put together because I needed a way to pull the MySQL version number from the server without actually having a connection. This was due to being part of a server info screen prior....

    Here is something I put together because I needed a way to pull the MySQL version number from the server without actually having a connection.  This was due to being part of a server info screen prior to installation of a cms.  Users need to know if their MySQL is supported or not prior to installation right? :)

    This will scrape the phpinfo page looking for the MySQL row that says Client API version and return the version number after it.  This could also be used to scrape just about anything from the phpinfo page. :)

    ob_start();

    phpinfo(INFO_MODULES);

    $info = ob_get_contents();

    ob_end_clean();

    $info = stristr($info, 'Client API version');

    preg_match('/[1-9].[0-9].[1-9][0-9]/', $info, $match);

    $gd = $match[0];

    echo 'MySQL:  '.$gd.'
    ';

    This will output:

    MySQL: 4.1.22 (which is the version on my server)

    I know this is crude but it's the only thing I could come up with and there isn't anything like this info available online so here it is.  I suck at preg_match and it would be helpful if someone could modify the string here to stand the test of time.

    展开全文
  • * Pause processing until the specified time, to avoid hammering a DB or service** @param int $target_time Timestamp* @param int $min_sleep Always sleep for a minimum number of seconds,* even if the...
  • I find this function incredibly useful when manipulating or creating images in php (with GD).I spent quite a while searching through a large number of included files to find where I had a undesired sp...
  • java.lang.Number.intValue()是java中的内置方法,该方法将指定数字的值作为int返回。这可能涉及舍入或截断。用法:public abstract ...以下示例程序旨在说明Number.intValue()方法:示例1:// java program to demo...
  • sql语句中的in用法示例SELECT TOP is used to return the number of records, it is very fast and its performance is very good. It is very useful for the large database having thousands of records. ...
  • java.lang.Number.byteValue()是java中的内置方法,它以字节为单位返回指定数字的值。这可能涉及舍入或截断。...以下示例程序旨在说明Number.byteValue()方法的使用:示例1:// Java program to illustrate...
  • unix 命令行 manLinux man command is the number one helper to get more detailed information about Linux commands. There are different alternatives like infobut man is a de-facto command for help. In ...
  • Java中的Period类的getDays()方法用于获取当前使用该期间的天数。...以下示例程序旨在说明上述方法:示例1:// Java code to show the function getDays()// to get number of days from given periodim...
  • 將小數轉換為二進製始終是python dev項目和競爭性編程中所必需的重要實用程序。具有速記功能來實現此目的在需要快速轉換而...使用遞歸# Function to print binary number for the# input decimal using recursiondef...
  • Java中Period类的getMonths()方法用于获取当前使用该月的月数。用法:public int getMonths()参数:...以下示例程序旨在说明上述方法:示例1:// Java code to show the function getMonths()// to get number of mon...
  • Python提供了一个内置函数round(),该函数会四舍五入为给定的位数,并...用法:round(number, number of digits)round()参数:..1) number - number to be rounded..2) number of digits (Optional) - number of d...
  • Java中的Period的getYears()方法用于获取该周期使用的年数。注意:15个月不等于1年3个月。...以下示例程序旨在说明上述方法:程序1:// Java code to show the function getYears()// to get the number of yea...
  • Python用其语言允许进行各种数学运算,这在科学领域具有...用法:math.gamma(x)参数:x:The number whose gamma value needs to be computed.返回值:伽玛值,在数值上等于“factorial(x-1)”。代码1:演示gamma()...
  • 将小数转换为二进制始终是python dev项目和竞争性编程中所必需的重要实用程序。具有速记功能来实现此目的在需要快速转换而...使用递归# Function to print binary number for the# input decimal using recursiondef...
  • 本文实例讲述了Python中pow()和math.pow()函数用法。分享给大家供大家参考,具体如下: 1. 内置函数pow() >>> help(pow) Help on built-in function pow in module __builtin__: pow(...) pow(x, y[, z]) -> ...
  • Oracle8i_9i数据库基础

    2010-03-03 14:16:58
    第八章 一些高级的用法 188 §8.1 关于DECODE 188 §8.1.1 DECODE 中的if-then-else逻辑 188 §8.1.2 DECODE 的简单例子 188 §8.1.3 DECODE实现表的转置 189 §8.2 关于访问远程数据库 192 §8.2.1 数据库链接 192 ...
  • 这是一个基本用法示例: <?php require '/path/to/vendor/autoload.php' ; $ dispatcher = FastRoute \simpleDispatcher ( function ( FastRoute \ RouteCollector $ r ) { $ r -> addRoute ( 'GET' , '/users'...
  • ZendFramework中文文档

    2011-03-22 10:11:12
    3.2.3. 高级用法示例 3.3. 摘要式认证 3.3.1. 简介 3.3.2. 规范(Specifics) 3.3.3. 身份(Identity) 3.4. HTTP 认证适配器 3.4.1. 简介 3.4.2. 设计回顾 3.4.3. 配置选项 3.4.4. Resolvers 3.4.4.1. ...
  • adb1.0.26包含fastboot.exe

    2019-03-05 15:11:03
    adb install [-lrtsdg] <path_to_apk> 参数: adb install 后面可以跟一些可选参数来控制安装 APK 的行为,可用参数及含义如下: 参数 含义 -l 将应用安装到保护目录 /mnt/asec -r 允许覆盖安装 -t 允许安装 ...
  • path_to_apk> 参数: adb install 后面可以跟一些可选参数来控制安装 APK 的行为,可用参数及含义如下: 参数 含义 -l 将应用安装到保护目录 /mnt/asec -r 允许覆盖安装 -t 允许安装 AndroidManifest....
  • 用法示例 >>> import jieba >>> import jieba.posseg as pseg >>> words = pseg.cut("我爱北京天安门") #jieba默认模式 >>> jieba.enable_paddle() #启动paddle模式。 0.40版...
  • print("清洗后:", ht0.clean_text(text1, to_url=True, remove_url=False)) # 处理HTML转义字符 text1 = "&lt;a c&gt;&nbsp;&#x27;&#x27;" print("HTML转正常字符") print("原:", text1) ...
  • alter table student add foreign key(classes_name, classes_number) referencesclasses(name, number); 自引用、自关联(递归表、树状表) create table tree( id int auto_increment primary key, name varchar...
  • C++MFC教程

    热门讨论 2013-05-21 13:37:15
    5、示例:下面有一段伪代码演示如何在窗口过程中处理消息 LONG yourWndProc(HWND hWnd,UINT uMessageType,WPARAM wP,LPARAM) { switch(uMessageType) { //使用SWITCH语句将各种消息分开 case(WM_PAINT): ...
  • 查看c_module示例。 -x 字节交换输出(仅用于交叉编译)。 -flto 使用链接时间优化。编译速度较慢,但可执行文件更小更快。使用选项时会自动设置此选项-fno-x。 -fno-[eval|string-normalize|regexp|json|proxy|map|...
  • PostgreSQL必备参考手册--详细书签版

    热门讨论 2013-02-04 13:28:35
    TO_NUMBER 112 TO_TIMESTAMP 112 4.4 几何类函数 112 AREA 112 BOX 113 CENTER 113 CIRCLE 113 DIAMETER 113 HEIGHT 114 ISCLOSED 114 ISOPEN 114 LENGTH 114 LSEG 114 NPOINT 115 PATH 115 PCLOSE...
  • 5.右击登录按钮选择go to slot,再选择clicked(),然后进入其单击事件的槽 函数,写入一句 void loginDlg::on_loginBtn_clicked() { accept(); } 6.改写main.cpp: #include #include "widget.h" #include "logindlg...

空空如也

空空如也

1 2
收藏数 39
精华内容 15
关键字:

to_number用法示例