예제 #1
0
def encrypt_key(dict_key, email):
	"""
	Generates a hexadecimal key for use with the official MDict program.
	
	dict_key and email should be of type bytes (representing ascii strings), and outfile should be a file
	open for writing in text mode.
	
	Returns a string of 32 hexadecimal digits. This should be placed in a file of its own, with
	the same name and location as the mdx file but the extension changed to '.key'. """
	
	email_digest = ripemd128(email)
	dict_key_digest = ripemd128(dict_key)
	
	s20 = Salsa20(key=email_digest,IV=b"\x00"*8,rounds=8)
	output_key = s20.encryptBytes(dict_key_digest)
	return _hexdump(output_key)
예제 #2
0
def _salsa_encrypt(plaintext, dict_key):
	if(type(dict_key) == str):
		dict_key = dict_key.encode("utf8")
	assert(type(dict_key) == bytes)
	assert(type(plaintext) == bytes)
	encrypt_key = ripemd128(dict_key)
	s20 = Salsa20(key=encrypt_key,IV=b"\x00"*8,rounds=8)
	return s20.encryptBytes(plaintext)
예제 #3
0
def encrypt_key(dict_key, **kwargs):
	"""
	Generates a hexadecimal key for use with the official MDict program.

	Parameters:
	  dict_key: a bytes object, representing the dictionary password.

	Keyword parameters:
	  Exactly one of email and device_id should be specified. They should be unicode strings,
	  representing either the user's email address, or the device ID of the machine on which
	  the dictionary is to be opened.
	
	Return value:
	  a string of 32 hexadecimal digits. This should be placed in a file of its own,
	  with the same name and location as the mdx file but the extension changed to '.key'.

	Example usage:
		key = encrypt_key(b"password", email="*****@*****.**")

		key = encrypt_key(b"password", device_id="12345678-9012-3456-7890-1234")
	"""

	if(("email" not in kwargs and "device_id" not in kwargs) or ("email" in kwargs and "device_id" in kwargs)):
		raise ParameterError("Expected exactly one of email and device_id as keyword argument")


	if "email" in kwargs:
		owner_info_digest = ripemd128(kwargs["email"].encode("ascii"))
	else:
		owner_info_digest = ripemd128(kwargs["device_id"].encode("ascii"))

	dict_key_digest = ripemd128(dict_key)
	
	s20 = Salsa20(key=owner_info_digest,IV=b"\x00"*8,rounds=8)
	output_key = s20.encryptBytes(dict_key_digest)
	return _hexdump(output_key)
예제 #4
0
def _mdx_encrypt(comp_block):
	key = ripemd128(comp_block[4:8] + struct.pack(b"<L", 0x3695))
	return comp_block[0:8] + _fast_encrypt(comp_block[8:], key)
예제 #5
0
파일: readmdict.py 프로젝트: ltf/lab
def _decrypt_regcode_by_deviceid(reg_code, deviceid):
    deviceid_digest = ripemd128(deviceid)
    s20 = Salsa20(key=deviceid_digest, IV=b"\x00"*8, rounds=8)
    encrypt_key = s20.encryptBytes(reg_code)
    return encrypt_key
예제 #6
0
파일: readmdict.py 프로젝트: ltf/lab
def _decrypt_regcode_by_email(reg_code, email):
    email_digest = ripemd128(email.decode().encode('utf-16-le'))
    s20 = Salsa20(key=email_digest, IV=b"\x00"*8, rounds=8)
    encrypt_key = s20.encryptBytes(reg_code)
    return encrypt_key
예제 #7
0
def _decrypt_regcode_by_deviceid(reg_code, deviceid):
    deviceid_digest = ripemd128(deviceid)
    s20 = Salsa20(key=deviceid_digest, IV=b"\x00" * 8, rounds=8)
    encrypt_key = s20.encryptBytes(reg_code)
    return encrypt_key
예제 #8
0
파일: readmdict.py 프로젝트: ltf/lab
def _mdx_decrypt(comp_block):
    key = ripemd128(comp_block[4:8] + pack(b'<L', 0x3695))
    return comp_block[0:8] + _fast_decrypt(comp_block[8:], key)
예제 #9
0
def _mdx_decrypt(comp_block):
    key = ripemd128(comp_block[4:8] + pack(b'<L', 0x3695))
    return comp_block[0:8] + _fast_decrypt(comp_block[8:], key)
예제 #10
0
def _decrypt_regcode_by_email(reg_code, email):
    email_digest = ripemd128(email.decode().encode('utf-16-le'))
    s20 = Salsa20(key=email_digest, IV=b"\x00" * 8, rounds=8)
    encrypt_key = s20.encryptBytes(reg_code)
    return encrypt_key
예제 #11
0
def _salsa_encrypt(plaintext, dict_key):
    assert (type(dict_key) == bytes)
    assert (type(plaintext) == bytes)
    encrypt_key = ripemd128(dict_key)
    s20 = Salsa20(key=encrypt_key, IV=b"\x00" * 8, rounds=8)
    return s20.encryptBytes(plaintext)
예제 #12
0
def _salsa_decrypt(ciphertext, dict_key):
    assert (type(ciphertext) == bytes)
    assert (type(dict_key) == bytes)
    decrypt_key = ripemd128(dict_key)
    s20 = Salsa20(key=decrypt_key, IV=b"\x00" * 8, rounds=8)
    return s20.encryptBytes(ciphertext)
예제 #13
0
def _mdx_encrypt(comp_block):
    key = ripemd128(comp_block[4:8] + pack(b"<L", 0x3695))
    return comp_block[0:8] + _fast_encrypt(comp_block[8:], key)