# Joël Simoneau # Submission for ROSALIND import os, sys relPath = os.path.abspath("..") if relPath not in sys.path: sys.path.insert(0, relPath) import tools.files as tf # Import file filename = '4_IPRB.txt' file = os.path.join(relPath, 'inputData', filename) data = tf.read_file(file).split() def mendel(k, m, n): up = k * (k - 1) + 2 * k * (m + n) + 3 * m * (m - 1) / 4 + n * m down = (k + m + n) * (k + m + n - 1) return up / down print(mendel(int(data[0]), int(data[1]), int(data[2])))
# Joël Simoneau # Submission for ROSALIND import os, sys relPath = os.path.abspath("..") if relPath not in sys.path: sys.path.insert(0, relPath) import tools.files as tf # Import file filename = '5_FIB.txt' file = os.path.join(relPath, 'inputData', filename) data = [int(N) for N in tf.read_file(file).split()] def fiboRabbit(n, k): rabbit = [1, 1] for i in range(n - 2): rabbit.append(rabbit[i] * k + rabbit[i + 1]) return rabbit print(fiboRabbit(data[0], data[1])[-1])
#Joël Simoneau #Submission for ROSALIND import os, sys relPath = os.path.abspath("..") if relPath not in sys.path: sys.path.insert(0, relPath) import tools.files as tf import tools.sequence as ts # Import file filename = '2_RNA.txt' file = os.path.join(relPath, 'inputData', filename) # Create sequence object sequence = ts.Sequence(tf.read_file(file)) sequence.dna2rna() print(sequence.sequence)
def create(dlc_name: str, keep_decrypted: bool = False): dlc_info = json.loads(read_file("src/" + dlc_name + ".json")) # Create info.bin info_bin = bytearray(20) put_uint32(info_bin, 0x00, dlc_info["Unk0"]) put_uint32(info_bin, 0x04, dlc_info["Unk4"]) put_uint32(info_bin, 0x08, dlc_info["LetterId"]) put_uint32(info_bin, 0x0C, dlc_info["UnkC"]) put_uint32(info_bin, 0x10, dlc_info["Unk10"]) item_file_name = dlc_info["ItemFile"] design_file_name = dlc_info["DesignFile"] npc_file_name = dlc_info["NpcFile"] if item_file_name: item_data = read_file("items/" + item_file_name) itemnames = get_item_names(item_data) else: item_data = None itemnames = None design_data = read_file("designs/" + design_file_name) if design_file_name else None npc_data = read_file("npcs/" + npc_file_name) if npc_file_name else None # Create separate distributables for each target region for region in dlc_info["Regions"]: # Create basic archive archive = U8() archive.add_file("info.bin", info_bin) # Add contents to archive if item_data: archive.add_file("item.bin", item_data) if region == "E" or region == "All": archive.add_file( "ltrue.bmg", create_letter(dlc_info, "UsEnglish", itemnames)) archive.add_file( "ltruf.bmg", create_letter(dlc_info, "UsFrench", itemnames)) archive.add_file( "ltrus.bmg", create_letter(dlc_info, "UsSpanish", itemnames)) if region == "P" or region == "All": archive.add_file( "ltree.bmg", create_letter(dlc_info, "EuEnglish", itemnames)) archive.add_file( "ltref.bmg", create_letter(dlc_info, "EuFrench", itemnames)) archive.add_file("ltreg.bmg", create_letter(dlc_info, "German", itemnames)) archive.add_file("ltrei.bmg", create_letter(dlc_info, "Italian", itemnames)) archive.add_file( "ltres.bmg", create_letter(dlc_info, "EuSpanish", itemnames)) if region == "J" or region == "All": archive.add_file( "ltrjj.bmg", create_letter(dlc_info, "Japanese", itemnames)) if region == "K" or region == "All": archive.add_file("ltrkk.bmg", create_letter(dlc_info, "Korean", itemnames)) if design_data: archive.add_file("design.bin", design_data) if npc_data: archive.add_file(npc_file_name, npc_data) # Save and encrypt the archive if possible output = archive.save() out_path = "build/" + dlc_name + "_" + region + ".arc" if is_wc24_keys_available(): if keep_decrypted: write_file(out_path, output) out_path += ".wc24" output = encrypt(output) else: print("Skipped RSA-AES signing due to missing key(s).") write_file(out_path, output)
import os import pyaes import rsa from tools.bitconv import get_uint32, get_bytes, put_uint8, put_uint32, put_bytes from tools.files import read_file WC24_MAGIC = 0x57433234 WC24_HEADER_SIZE = 0x30 INIT_VECTOR_OFFSET = 0x30 INIT_VECTOR_SIZE = 16 SIGNATURE_OFFSET = 0x40 SIGNATURE_SIZE = 256 DATA_OFFSET = 0x140 RSA_KEY = read_file("rvforestdl.pem.bin") AES_KEY = read_file("rvforestdl.aes.bin") def is_wc24_keys_available() -> bool: return RSA_KEY and AES_KEY def decrypt(data) -> bytes: if not is_wc24_keys_available(): raise Exception("RSA-AES keys not initialized. Can't decrypt data.") if get_uint32(data, 0x00) != WC24_MAGIC: raise Exception("Error: No WC24 data given. Can't extract U8 data.") iv = get_bytes(data, INIT_VECTOR_OFFSET, INIT_VECTOR_SIZE) aes = pyaes.AESModeOfOperationOFB(AES_KEY, iv=iv)