示例#1
1
文件: DES+NNT.cpp 项目: imace/nnt
void des::decrypt(char const* key, core::vector<byte> const& in, core::string& out)
{
    DES_cblock key_block;
    DES_key_schedule schedule;
    DES_string_to_key(key, &key_block);
    DES_set_key_checked(&key_block, &schedule);

    char* buf = (char*)malloc(in.size());

    core::vector<byte>::const_iterator iter = in.begin();
    DES_cblock* output = (DES_cblock*)buf;

    DES_cblock input;
    while (iter != in.end())
    {
        usize sz = in.end() - iter;
        if (sz >= 8)
            sz = 8;
        else
            memset(input, 0, sizeof(DES_cblock));
        memcpy(input, &*iter, sz);
        DES_ecb_encrypt(&input, output, &schedule, DES_DECRYPT);
        iter += sz;
        output += 1;
    }

    out = buf;

    free(buf);
}
示例#2
0
文件: packages.cpp 项目: Botyto/Core
	bool output_pack(const core::string & packname, const core::vector<pack_entry> & entries)
	{
		//Final package output path
		string outpack = settings::packs_out + packname + "." + settings::extension;

		//Package writer
		fwriter writer(outpack, true);
		if (!writer.opened() || !writer.ok())
			return false;

		//Iterate entires
		writer.write_uint16((uint16_t)entries.size());
		for (auto e : entries)
		{
			console::print("[Packs] Packaging file (%) '%'", e.type, e.file);

			//Write file type
			writer.write_uint8((uint8_t)e.type);
			//Write file name size
			writer.write_uint8((uint8_t)e.file.size());
			//Write file name
			writer.write(e.file);

			string path = e.dir + e.file;

			//Write file size
			writer.write_uint32((uint32_t)io::size(path));
			//Write file contents
			if (!io::append_content(path, writer))
				return false;
		}

		writer.close();
		return true;
	}