import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.spec.AlgorithmParameterSpec;
public class BlowfishTest {
// 密钥算法名称
public static final String BLOWFISH = "Blowfish";
// 转换模式
public static final String TRANSFORMATION = "Blowfish/CBC/PKCS5Padding";
public static byte[] encrypt(String key, byte[] text, String initializationVector)throws Exception {
// 根据给定的字节数组构造一个密钥 Blowfish-与给定的密钥内容相关联的密钥算法的名称
SecretKeySpec sksSpec = new SecretKeySpec(key.getBytes(), BLOWFISH);
// 使用 initializationVector 中的字节作为 IV 来构造一个 IvParameterSpec 对象
AlgorithmParameterSpec iv = new IvParameterSpec(initializationVector.getBytes());
// 返回实现指定转换的 Cipher 对象
Cipher cipher = Cipher.getInstance(TRANSFORMATION);
// 用密钥和随机源初始化此 Cipher
cipher.init(Cipher.ENCRYPT_MODE, sksSpec, iv);
// 加密文本
byte[] encrypted = cipher.doFinal(text);
return encrypted;
}
public static byte[] decrypt(String key, byte[] text, String initializationVector)throws Exception {
SecretKeySpec skeSpect = new SecretKeySpec(key.getBytes(), BLOWFISH);
AlgorithmParameterSpec iv = new IvParameterSpec(initializationVector.getBytes());
Cipher cipher = Cipher.getInstance(TRANSFORMATION);
cipher.init(Cipher.DECRYPT_MODE, skeSpect, iv);
byte[] decrypted = cipher.doFinal(text);
return decrypted;
}
}
import re
import configparser
def MmlCmdToMmlHelp(mmlCmd):
mmlHelp = mmlCmd
mmlHelp = mmlHelp.lower().replace(' ','_')
return mmlHelp + '.xml'
def MmlHelpToMmlCmd(mmlHelp):
mmlCmd = mmlHelp
mmlCmd = mmlCmd.replace('.xml','')
mmlCmd = mmlCmd.upper().replace('_',' ')
return mmlCmd
def getMmlFromMacroByType(macro_name, mml_type):
mmlList =[]
config = configparser.ConfigParser()
config.read('macro.ini')
for section in config.sections():
if 'isnotshow' in config.options(section):
Type = int(config.get(section,"isnotshow"))
else:
Type = 0
if(Type == mml_type):
mmlList.append(section)
return mmlList
def getMmlFromDitemap(ditemap_name):
mmlList =[]
file= open(ditemap_name)
try:
fileContext = file.read()
finally:
file.close()
for mml in re.findall(r'<topic name = "mml/([\s\S]*?)"></topic>',fileContext,re.M):
mmlList.append(MmlHelpToMmlCmd(mml))
return mmlList
def getNeedAddFromDitemap(ditemapList, macroList):
mmlList = []
for mml in macroList:
if mml not in ditemapList:
mmlList.append(MmlCmdToMmlHelp(mml))
return mmlList
def getNeedRmvFromDitemap(ditemapList, macroList):
mmlList = []
for mml in ditemapList:
if mml not in macroList:
mmlList.append(MmlCmdToMmlHelp(mml))
return mmlList
if __name__ == '__main__':
ditemap_name = "mml.ditemap"
macro_name = 'macro.ini'
mml_type = 3
MacroMmlList = getMmlFromMacroByType(macro_name, mml_type)
DitemapMmlList = getMmlFromDitemap(ditemap_name)
needAddList = getNeedAddFromDitemap(DitemapMmlList,MacroMmlList)
needRmvList = getNeedRmvFromDitemap(DitemapMmlList,MacroMmlList)
print ('MacroMmlList = ',MacroMmlList)
print ('DitemapMmlList = ',DitemapMmlList)
print ('needAddList = ',needAddList)
print ('needRmvList = ',needRmvList)
print ("end__")
add...