Skip to content

Commit 63247fa

Browse files
committed
chore(sha256_example): use array_fn
1 parent 799291a commit 63247fa

File tree

1 file changed

+3
-68
lines changed

1 file changed

+3
-68
lines changed

tfhe/examples/sha256_bool/boolean_ops.rs

Lines changed: 3 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -313,76 +313,11 @@ mod tests {
313313
bool_arr
314314
}
315315
fn encrypt(bools: &[bool; 32], ck: &ClientKey) -> [Ciphertext; 32] {
316-
[
317-
ck.encrypt(bools[0]),
318-
ck.encrypt(bools[1]),
319-
ck.encrypt(bools[2]),
320-
ck.encrypt(bools[3]),
321-
ck.encrypt(bools[4]),
322-
ck.encrypt(bools[5]),
323-
ck.encrypt(bools[6]),
324-
ck.encrypt(bools[7]),
325-
ck.encrypt(bools[8]),
326-
ck.encrypt(bools[9]),
327-
ck.encrypt(bools[10]),
328-
ck.encrypt(bools[11]),
329-
ck.encrypt(bools[12]),
330-
ck.encrypt(bools[13]),
331-
ck.encrypt(bools[14]),
332-
ck.encrypt(bools[15]),
333-
ck.encrypt(bools[16]),
334-
ck.encrypt(bools[17]),
335-
ck.encrypt(bools[18]),
336-
ck.encrypt(bools[19]),
337-
ck.encrypt(bools[20]),
338-
ck.encrypt(bools[21]),
339-
ck.encrypt(bools[22]),
340-
ck.encrypt(bools[23]),
341-
ck.encrypt(bools[24]),
342-
ck.encrypt(bools[25]),
343-
ck.encrypt(bools[26]),
344-
ck.encrypt(bools[27]),
345-
ck.encrypt(bools[28]),
346-
ck.encrypt(bools[29]),
347-
ck.encrypt(bools[30]),
348-
ck.encrypt(bools[31]),
349-
]
316+
array::from_fn(|i| ck.encrypt(bools[i]))
350317
}
318+
351319
fn decrypt(bools: &[Ciphertext; 32], ck: &ClientKey) -> [bool; 32] {
352-
[
353-
ck.decrypt(&bools[0]),
354-
ck.decrypt(&bools[1]),
355-
ck.decrypt(&bools[2]),
356-
ck.decrypt(&bools[3]),
357-
ck.decrypt(&bools[4]),
358-
ck.decrypt(&bools[5]),
359-
ck.decrypt(&bools[6]),
360-
ck.decrypt(&bools[7]),
361-
ck.decrypt(&bools[8]),
362-
ck.decrypt(&bools[9]),
363-
ck.decrypt(&bools[10]),
364-
ck.decrypt(&bools[11]),
365-
ck.decrypt(&bools[12]),
366-
ck.decrypt(&bools[13]),
367-
ck.decrypt(&bools[14]),
368-
ck.decrypt(&bools[15]),
369-
ck.decrypt(&bools[16]),
370-
ck.decrypt(&bools[17]),
371-
ck.decrypt(&bools[18]),
372-
ck.decrypt(&bools[19]),
373-
ck.decrypt(&bools[20]),
374-
ck.decrypt(&bools[21]),
375-
ck.decrypt(&bools[22]),
376-
ck.decrypt(&bools[23]),
377-
ck.decrypt(&bools[24]),
378-
ck.decrypt(&bools[25]),
379-
ck.decrypt(&bools[26]),
380-
ck.decrypt(&bools[27]),
381-
ck.decrypt(&bools[28]),
382-
ck.decrypt(&bools[29]),
383-
ck.decrypt(&bools[30]),
384-
ck.decrypt(&bools[31]),
385-
]
320+
array::from_fn(|i| ck.decrypt(&bools[i]))
386321
}
387322

388323
#[test]

0 commit comments

Comments
 (0)