Advertisement
solomonu

Untitled

Mar 15th, 2020
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.67 KB | None | 0 0
  1. use std::io::{stdin, BufRead};
  2.  
  3. fn print_state(state: [[u8; 8]; 8]) {
  4.     for i in 0..8 {
  5.         for j in 0..8 {
  6.             print!("{}", state[i][j] as char);
  7.         }
  8.         println!();
  9.     }
  10. }
  11.  
  12. fn main() {
  13.     println!("What do you want to encode?");
  14.     let mut input_buf = String::new();
  15.     stdin().lock().read_line(&mut input_buf).expect("Cannot read input.");
  16.     let input = input_buf.trim();
  17.     assert!(input.len() == 32);
  18.     let mut buf = [[b'@'; 8]; 8];
  19.     for (i, c) in input.chars().enumerate() {
  20.         for j in 0..8 {
  21.             buf[j][(i + j) % 8] |= (((c as u8) & (1 << j)) >> j) << (i / 8);
  22.         }
  23.     }
  24.     print_state(buf);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement