Skip to content

Commit

Permalink
implemnt bindings for alphabet generation
Browse files Browse the repository at this point in the history
  • Loading branch information
gogo2464 committed Aug 28, 2023
1 parent 85c1564 commit 2eeada4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
12 changes: 5 additions & 7 deletions cryptatools-core/binding-testing/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,9 @@



from cryptatools_core.utils.alphabets import Encoding, Alphabet








a = Alphabet.full_hexadecimal_alphabet()
hex_alphabet = [{d.str: d.bytes} for d in a.get_encoding()]
assert hex_alphabet == [{'00': [0]}, {'01': [1]}, {'02': [2]}, {'03': [3]}, {'04': [4]}, {'05': [5]}, {'06': [6]}, {'07': [7]}, {'08': [8]}, {'09': [9]}, {'0a': [10]}, {'0b': [11]}, {'0c': [12]}, {'0d': [13]}, {'0e': [14]}, {'0f': [15]}, {'10': [16]}, {'11': [17]}, {'12': [18]}, {'13': [19]}, {'14': [20]}, {'15': [21]}, {'16': [22]}, {'17': [23]}, {'18': [24]}, {'19': [25]}, {'1a': [26]}, {'1b': [27]}, {'1c': [28]}, {'1d': [29]}, {'1e': [30]}, {'1f': [31]}, {'20': [32]}, {'21': [33]}, {'22': [34]}, {'23': [35]}, {'24': [36]}, {'25': [37]}, {'26': [38]}, {'27': [39]}, {'28': [40]}, {'29': [41]}, {'2a': [42]}, {'2b': [43]}, {'2c': [44]}, {'2d': [45]}, {'2e': [46]}, {'2f': [47]}, {'30': [48]}, {'31': [49]}, {'32': [50]}, {'33': [51]}, {'34': [52]}, {'35': [53]}, {'36': [54]}, {'37': [55]}, {'38': [56]}, {'39': [57]}, {'3a': [58]}, {'3b': [59]}, {'3c': [60]}, {'3d': [61]}, {'3e': [62]}, {'3f': [63]}, {'40': [64]}, {'41': [65]}, {'42': [66]}, {'43': [67]}, {'44': [68]}, {'45': [69]}, {'46': [70]}, {'47': [71]}, {'48': [72]}, {'49': [73]}, {'4a': [74]}, {'4b': [75]}, {'4c': [76]}, {'4d': [77]}, {'4e': [78]}, {'4f': [79]}, {'50': [80]}, {'51': [81]}, {'52': [82]}, {'53': [83]}, {'54': [84]}, {'55': [85]}, {'56': [86]}, {'57': [87]}, {'58': [88]}, {'59': [89]}, {'5a': [90]}, {'5b': [91]}, {'5c': [92]}, {'5d': [93]}, {'5e': [94]}, {'5f': [95]}, {'60': [96]}, {'61': [97]}, {'62': [98]}, {'63': [99]}, {'64': [100]}, {'65': [101]}, {'66': [102]}, {'67': [103]}, {'68': [104]}, {'69': [105]}, {'6a': [106]}, {'6b': [107]}, {'6c': [108]}, {'6d': [109]}, {'6e': [110]}, {'6f': [111]}, {'70': [112]}, {'71': [113]}, {'72': [114]}, {'73': [115]}, {'74': [116]}, {'75': [117]}, {'76': [118]}, {'77': [119]}, {'78': [120]}, {'79': [121]}, {'7a': [122]}, {'7b': [123]}, {'7c': [124]}, {'7d': [125]}, {'7e': [126]}, {'7f': [127]}, {'80': [128]}, {'81': [129]}, {'82': [130]}, {'83': [131]}, {'84': [132]}, {'85': [133]}, {'86': [134]}, {'87': [135]}, {'88': [136]}, {'89': [137]}, {'8a': [138]}, {'8b': [139]}, {'8c': [140]}, {'8d': [141]}, {'8e': [142]}, {'8f': [143]}, {'90': [144]}, {'91': [145]}, {'92': [146]}, {'93': [147]}, {'94': [148]}, {'95': [149]}, {'96': [150]}, {'97': [151]}, {'98': [152]}, {'99': [153]}, {'9a': [154]}, {'9b': [155]}, {'9c': [156]}, {'9d': [157]}, {'9e': [158]}, {'9f': [159]}, {'a0': [160]}, {'a1': [161]}, {'a2': [162]}, {'a3': [163]}, {'a4': [164]}, {'a5': [165]}, {'a6': [166]}, {'a7': [167]}, {'a8': [168]}, {'a9': [169]}, {'aa': [170]}, {'ab': [171]}, {'ac': [172]}, {'ad': [173]}, {'ae': [174]}, {'af': [175]}, {'b0': [176]}, {'b1': [177]}, {'b2': [178]}, {'b3': [179]}, {'b4': [180]}, {'b5': [181]}, {'b6': [182]}, {'b7': [183]}, {'b8': [184]}, {'b9': [185]}, {'ba': [186]}, {'bb': [187]}, {'bc': [188]}, {'bd': [189]}, {'be': [190]}, {'bf': [191]}, {'c0': [192]}, {'c1': [193]}, {'c2': [194]}, {'c3': [195]}, {'c4': [196]}, {'c5': [197]}, {'c6': [198]}, {'c7': [199]}, {'c8': [200]}, {'c9': [201]}, {'ca': [202]}, {'cb': [203]}, {'cc': [204]}, {'cd': [205]}, {'ce': [206]}, {'cf': [207]}, {'d0': [208]}, {'d1': [209]}, {'d2': [210]}, {'d3': [211]}, {'d4': [212]}, {'d5': [213]}, {'d6': [214]}, {'d7': [215]}, {'d8': [216]}, {'d9': [217]}, {'da': [218]}, {'db': [219]}, {'dc': [220]}, {'dd': [221]}, {'de': [222]}, {'df': [223]}, {'e0': [224]}, {'e1': [225]}, {'e2': [226]}, {'e3': [227]}, {'e4': [228]}, {'e5': [229]}, {'e6': [230]}, {'e7': [231]}, {'e8': [232]}, {'e9': [233]}, {'ea': [234]}, {'eb': [235]}, {'ec': [236]}, {'ed': [237]}, {'ee': [238]}, {'ef': [239]}, {'f0': [240]}, {'f1': [241]}, {'f2': [242]}, {'f3': [243]}, {'f4': [244]}, {'f5': [245]}, {'f6': [246]}, {'f7': [247]}, {'f8': [248]}, {'f9': [249]}, {'fa': [250]}, {'fb': [251]}, {'fc': [252]}, {'fd': [253]}, {'fe': [254]}, {'ff': [255]}], f"cipher={hex_alphabet} incorrect alphabet."
print("encoding = {0}. OK!".format(hex_alphabet))
4 changes: 3 additions & 1 deletion cryptatools-core/src/cryptatools.udl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ interface Alphabet {
constructor(sequence<Encoding> encoding);
[Name=new_empty]
constructor();
[Name=full_hexadecimal_alphabet]
constructor();
sequence<Encoding> get_encoding();
};

Expand All @@ -31,4 +33,4 @@ interface CoincidenceIndexGuesser {
constructor(Alphabet alphabet);
double guess_coincidence_index(sequence<u8> cipher_text_input);
double guess_coincidence_index_statistics_from_file(string file_name);
};
};
7 changes: 7 additions & 0 deletions cryptatools-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,10 @@ use crate::cryptography::classical::encryption::transpositional_ciphers::columna
use crate::cryptanalysis::general_cryptanalysis_methods::frequency_analysis::coincidence_index::CoincidenceIndexGuesser;

uniffi_macros::include_scaffolding!("cryptatools");

/*
[Name=full_hexadecimal_alphabet]
constructor();
Alphabet full_hexadecimal_alphabet();
*/
4 changes: 1 addition & 3 deletions cryptatools-core/src/utils/alphabets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ impl Alphabet {
///
/// This method has no argument.
/// Returns an alphabet made with hexadecimal and lowercase only values.
pub fn full_hexadecimal_alphabet(&mut self) -> Self {
pub fn full_hexadecimal_alphabet() -> Self {
let mut encoding = BiBTreeMap::new();
encoding.insert(String::from("00"), vec![0x00]);
encoding.insert(String::from("01"), vec![0x01]);
Expand Down Expand Up @@ -671,8 +671,6 @@ impl Alphabet {
encoding.insert(String::from("fe"), vec![0xfe]);
encoding.insert(String::from("ff"), vec![0xff]);

self.encoding = encoding.clone();

Alphabet {
encoding: encoding
}
Expand Down
2 changes: 1 addition & 1 deletion doc-examples/ethereum-colision-evaluation/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const WSS_URL: &str = "wss://mainnet.infura.io/ws/v3/c60b0bb42f8a4c6481ecd229edd

#[tokio::main]
async fn main() -> eyre::Result<()> {
let hexadecimal_alphabet = Alphabet::new_empty().full_hexadecimal_alphabet();
let hexadecimal_alphabet = Alphabet::full_hexadecimal_alphabet();
let bp = BirtdayParadox::new(hexadecimal_alphabet.into());

let provider = Provider::<Ws>::connect(WSS_URL).await?;
Expand Down

0 comments on commit 2eeada4

Please sign in to comment.