本文目錄一覽:
- 1、python摩斯密碼轉換?
- 2、Python進行 AES CBC-128bit PKCS7/PKCS5 填充加密解密
- 3、請問…python編程中,怎麼解密base64編碼和zlib編碼?
- 4、如何使用Python進行Rijndael方式的加密解密
- 5、有關於python的摩斯密碼轉換?
python摩斯密碼轉換?
定義函數如下:
def get_sentence(code_list):return ‘ ‘.join(”.join(morse2char[e] for e in l) for l in code_list)
Python進行 AES CBC-128bit PKCS7/PKCS5 填充加密解密
你看一下這個例子吧。可以參考下面的地址:前面加上http,把句號改成點。
likang。me/blog/2013/06/05/python-pycrypto-aes-ecb-pkcs-5/
# -*- coding: utf-8 -*-
from Crypto.Cipher import AES
import os
BS = AES.block_size
pad = lambda s: s + (BS – len(s) % BS) * chr(BS – len(s) % BS)
unpad = lambda s : s[0:-ord(s[-1])]
key = os.urandom(16) # the length can be (16, 24, 32)
text = ‘to be encrypted’
cipher = AES.new(key)
encrypted = cipher.encrypt(pad(text)).encode(‘hex’)
print encrypted # will be something like ‘f456a6b0e54e35f2711a9fa078a76d16’
decrypted = unpad(cipher.decrypt(encrypted.decode(‘hex’)))
print decrypted # will be ‘to be encrypted’
請問…python編程中,怎麼解密base64編碼和zlib編碼?
import base64,zlib
’‘’解密base64編碼‘’‘
a=base64.b64decode(‘解碼內容’)
’‘’解密zlib編碼‘’‘
b=zlib.decompress(‘解碼內容‘)
如何使用Python進行Rijndael方式的加密解密
Rijndael,在高級加密標準(AES)中使用的基本密碼算法。
概述 (美國)國家標準技術研究所(NIST)選擇Rijndael作為美國政府加密標準(AES)的加密算法,AES取代早期的數據加密標準(DES)。Rijndael由比利時計算機科學家Vincent Rijmen和Joan Daemen開發,它可以使用128位,192位或者256位的密鑰長度,使得它比56位的DES更健壯可靠。Rijndael也有一個非常小的版本(52位),合適用在蜂窩電話、個人數字處理器(PDA)和其他的小設備上。
近似讀音:Rijn [rain] dael [del] (萊恩戴爾) Rijn 來源 Rhine [萊茵河]的荷蘭語(Dutch)發音。
dael 是常用的人名 這詞是兩個科學家的名字各出一段拼成的。
Rijndael.h
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#pragma once
#include exception
#include string.h
using namespace std;
class CRijndael
{
public:
enum { ECB=0, CBC=1, CFB=2 };
private:
enum { DEFAULT_BLOCK_SIZE=16 };
enum { MAX_BLOCK_SIZE=32, MAX_ROUNDS=14, MAX_KC=8, MAX_BC=8 };
static int Mul(int a, int b)
{
return (a != 0 b != 0) ? sm_alog[(sm_log[a 0xFF] + sm_log[b 0xFF]) % 255] : 0;
}
static int Mul4(int a, char b[])
{
if(a == 0)
return 0;
a = sm_log[a 0xFF];
int a0 = (b[0] != 0) ? sm_alog[(a + sm_log[b[0] 0xFF]) % 255] 0xFF : 0;
int a1 = (b[1] != 0) ? sm_alog[(a + sm_log[b[1] 0xFF]) % 255] 0xFF : 0;
int a2 = (b[2] != 0) ? sm_alog[(a + sm_log[b[2] 0xFF]) % 255] 0xFF : 0;
int a3 = (b[3] != 0) ? sm_alog[(a + sm_log[b[3] 0xFF]) % 255] 0xFF : 0;
return a0 24 | a1 16 | a2 8 | a3;
}
public:
CRijndael();
virtual ~CRijndael();
void MakeKey(char const* key, char const* chain,
int keylength=DEFAULT_BLOCK_SIZE, int blockSize=DEFAULT_BLOCK_SIZE);
private:
void Xor(char* buff, char const* chain)
{
if(false==m_bKeyInit)
throw exception(sm_szErrorMsg1);
for(int i=0; im_blockSize; i++)
*(buff++) ^= *(chain++);
}
void DefEncryptBlock(char const* in, char* result);
void DefDecryptBlock(char const* in, char* result);
public:
void EncryptBlock(char const* in, char* result);
void DecryptBlock(char const* in, char* result);
void Encrypt(char const* in, char* result, size_t n, int iMode=ECB);
void Decrypt(char const* in, char* result, size_t n, int iMode=ECB);
int GetKeyLength()
{
if(false==m_bKeyInit)
throw exception(sm_szErrorMsg1);
return m_keylength;
}
int GetBlockSize()
{
if(false==m_bKeyInit)
throw exception(sm_szErrorMsg1);
return m_blockSize;
}
int GetRounds()
{
if(false==m_bKeyInit)
throw exception(sm_szErrorMsg1);
return m_iROUNDS;
}
void ResetChain()
{
memcpy(m_chain, m_chain0, m_blockSize);
}
public:
static char const* sm_chain0;
private:
static const int sm_alog[256];
static const int sm_log[256];
static const char sm_S[256];
static const char sm_Si[256];
static const int sm_T1[256];
static const int sm_T2[256];
static const int sm_T3[256];
static const int sm_T4[256];
static const int sm_T5[256];
static const int sm_T6[256];
static const int sm_T7[256];
static const int sm_T8[256];
static const int sm_U1[256];
static const int sm_U2[256];
static const int sm_U3[256];
static const int sm_U4[256];
static const char sm_rcon[30];
static const int sm_shifts[3][4][2];
static char const* sm_szErrorMsg1;
static char const* sm_szErrorMsg2;
bool m_bKeyInit;
int m_Ke[MAX_ROUNDS+1][MAX_BC];
int m_Kd[MAX_ROUNDS+1][MAX_BC];
int m_keylength;
int m_blockSize;
int m_iROUNDS;
char m_chain0[MAX_BLOCK_SIZE];
char m_chain[MAX_BLOCK_SIZE];
int tk[MAX_KC];
int a[MAX_BC];
int t[MAX_BC];
};
有關於python的摩斯密碼轉換?
定義函數如下:
def get_code_list(unit_list):return [[”.join(‘s’ if e==’1′ else ‘L’ for e in s.split(‘0’)) for s in l] for l in unit_list]
原創文章,作者:0Q9JU,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/127908.html