OKlibrary  0.2.1.6
ConstraintTemplateTranslation.mac
Go to the documentation of this file.
00001 /* Matthew Gwynne, 6.12.2010 (Swansea) */
00002 /* Copyright 2010, 2011 Oliver Kullmann
00003 This file is part of the OKlibrary. OKlibrary is free software; you can redistribute
00004 it and/or modify it under the terms of the GNU General Public License as published by
00005 the Free Software Foundation and included in this library; either version 3 of the
00006 License, or any later version. */
00007 
00022 oklib_include("OKlib/ComputerAlgebra/DataStructures/Lisp/Lists.mac")$
00023 oklib_include("OKlib/ComputerAlgebra/Cryptology/Lisp/Cryptanalysis/Rijndael/ConstraintTemplateRewriteSystem.mac")$
00024 
00025 
00026 /********************************
00027  * Translation functions        *
00028  ********************************
00029 */
00030 
00031 /* Takes a list of constraint templates and a rewrite mapping and returns a
00032    clause-list where each constraint has been mapped to clauses by the
00033    function given in the rewrite mapping. */
00034 csttl2cl(csttl, rewrite_map) := block(
00035   [prog_l : 0, csttl_len : length(csttl),
00036    rewrite_hash : osm2hm(rewrite_map),cstr],
00037   lappend(map(
00038     lambda([a],block(
00039       if oklib_monitor then
00040         print("Translating '", first(a), "(",
00041           prog_l : prog_l + 1,"/",csttl_len,")"),
00042       cstrb : ev_hm(rewrite_hash, cstt_name(a)),
00043       if cstrb # false then cstrb[1](a) else (
00044         print("Warning: \"", cstt_name(a),
00045               "\" does not match any rewrite mapping! Mapped to []."),
00046         []))),
00047   csttl)))$
00048 
00049 csttl2fcl(csttl, var_list, rewrite_map) := block(
00050   [prog_l : 0, csttl_len : length(csttl),
00051    rewrite_hash : osm2hm(rewrite_map),cstr, new_var_list : var_list, cl],
00052   cl : lappend(map(
00053     lambda([a],block(
00054       if oklib_monitor then
00055         print("Translating '", first(a), "(",
00056           prog_l : prog_l + 1,"/",csttl_len,")"),
00057       cstrb : ev_hm(rewrite_hash, cstt_name(a)),
00058       if cstrb # false then block(
00059         new_var_list : append(new_var_list, cstrb[2](a)),
00060         cstrb[1](a))
00061       else (
00062         print("Warning: \"", cstt_name(a),
00063           "\" does not match any rewrite mapping! Mapped to []."),
00064         []))),
00065   csttl)),
00066   return([new_var_list, cl]))$
00067 
00068 
00069 /****************************************
00070  * Translation bundles                  *
00071  ****************************************
00072 */
00073 
00074 /* Constraint template translation bundle which does nothing
00075    (i.e no variables are introduced by it's
00076    rewrite function). */
00077 zero_cstttb : [lambda([[a]],[]), lambda([[a]],[])]$
00078