solomonu

Untitled

Mar 15th, 2020
562
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×