Skip to content

Commit b71f042

Browse files
committed
src/bin/gnit.rs:intermediate
1 parent c309317 commit b71f042

File tree

1 file changed

+129
-52
lines changed

1 file changed

+129
-52
lines changed

src/bin/gnit.rs

Lines changed: 129 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -102,38 +102,100 @@ mod foreign_crate {
102102
}
103103

104104
fn main() -> Result<(), std::io::Error> {
105-
let bhashwbhw = format!(
106-
"{}/{}/{}/{}",
107-
get_blockhash(),
108-
get_weeble(),
109-
get_blockheight(),
110-
get_wobble()
105+
//CAUTION: hash_of_string is different than hash.as_bytes_mut!
106+
107+
let mut weeble = get_weeble();
108+
println!("weeble={}", weeble);
109+
let mut weeble_string = get_weeble_string();
110+
let mut wobble = get_wobble();
111+
println!("wobble={}", wobble);
112+
let mut wobble_string = get_wobble_string();
113+
let mut blockheight = get_blockheight();
114+
println!("blockheight={}", blockheight);
115+
let mut blockheight_string = get_blockheight_string();
116+
println!("blockheight_string={}", blockheight_string);
117+
let mut blockhash = get_blockhash();
118+
println!("blockhash={}", blockhash);
119+
120+
let hash_of_weeble = sha256::Hash::hash(weeble.as_bytes_mut());
121+
println!("hash_of_weeble={}", hash_of_weeble);
122+
123+
let hash_of_weeble_string = sha256::Hash::hash(weeble_string.as_bytes());
124+
println!("hash_of_weeble_string={}", hash_of_weeble_string);
125+
126+
let hash_of_blockheight = sha256::Hash::hash(blockheight.as_bytes());
127+
println!("hash_of_blockheight={}", hash_of_blockheight);
128+
let hash_of_blockheight_string = sha256::Hash::hash(blockheight_string.as_bytes());
129+
println!(
130+
"hash_of_blockheight_string={}",
131+
(hash_of_blockheight_string)
111132
);
112-
//println!("{}", bhashwbhw);
113133

114-
//CAUTION: hash_of_string is different than hash.as_bytes_mut!
115-
//TODO: gnostr-bins: add from_str and from_bytes
116-
let hash_of_string_2000 = sha256::Hash::hash("2000".as_bytes());
117-
//println!("hash_of_string_2000={}", hash_of_string_2000);
118-
//println!("hash_of_string_2000={:x}", hash_of_string_2000);
134+
let hash_of_wobble = sha256::Hash::hash(wobble.as_bytes());
135+
println!("hash_of_wobble={}", hash_of_wobble);
119136

120-
//println!("get_weeble()={}", get_weeble());
121-
//println!("get_weeble_string()={}", get_weeble_string());
137+
let hash_of_wobble_string = sha256::Hash::hash(wobble_string.as_bytes());
138+
println!("hash_of_wobble_string={}", hash_of_wobble_string);
139+
140+
let hexd_weeble = hex::decode(format!("{}", hash_of_weeble));
141+
println!("hexd_weeble.unwrap()=\n{:?}", hexd_weeble.unwrap());
142+
let hexd_wobble = hex::decode(format!("{}", hash_of_wobble));
143+
println!("hexd_wobble.unwrap()=\n{:?}", hexd_wobble.unwrap());
144+
145+
let mut weeble_vec = Vec::new();
146+
let privkey = b"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
147+
//forward
148+
let mut count = 0;
149+
for byte in privkey.as_bytes() {
150+
print!("{}^{}={} ", count, byte, count ^ byte);
151+
weeble_vec.push(byte);
152+
count += 1;
153+
}
154+
println!("");
155+
//backwards
156+
let mut count = privkey.len() - 1;
157+
for byte in &weeble_vec {
158+
print!("{}^{} ", count, privkey[count]);
159+
count -= 1;
160+
}
161+
println!("");
162+
//symetry
163+
let privkey = b"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
164+
let mut privvirp = Vec::new();
165+
let mut count = privkey.len() - 1;
166+
for byte in &weeble_vec {
167+
print!("{}^{}={} ", *byte, privkey[count], *byte ^ privkey[count]);
168+
privvirp.push(*byte ^ privkey[count]);
169+
count -= 1;
170+
}
171+
println!("");
172+
for byte in &privvirp {
173+
print!("{:?} ", byte);
174+
}
122175

123-
let hash_of_weeble = sha256::Hash::hash(get_weeble().as_bytes_mut());
124-
//println!("hash_of_weeble={}", hash_of_weeble);
176+
//std::process::exit(0);
177+
//println!("weeble_vec={:?}", weeble_vec[0] ^ weeble_vec[0]);
178+
//println!("weeble_vec={:?}", weeble_vec[0] ^ weeble_vec[1]);
179+
//println!("weeble_vec[0]={}", weeble_vec[0]);
125180

126-
let hash_of_weeble_string = sha256::Hash::hash(get_weeble_string().as_bytes());
127-
//println!("hash_of_weeble_string={}", hash_of_weeble_string);
181+
//xor(hexd_weeble.unwrap(),hexd_wobble.unwrap());
128182

129-
let hash_of_blockheight = sha256::Hash::hash(get_blockheight().as_bytes_mut());
130-
//println!("hash_of_blockheight={}", hash_of_blockheight);
183+
let bhashwbhw = format!(
184+
"{}\n{}\n{}\n{}",
185+
get_blockhash(),
186+
get_weeble(),
187+
get_blockheight(),
188+
get_wobble()
189+
);
190+
println!("");
191+
println!("bhashwbhw={}", bhashwbhw);
131192

132-
let hash_of_wobble = sha256::Hash::hash(get_wobble().as_bytes_mut());
133-
//println!("hash_of_wobble={}", hash_of_wobble);
134-
//println!("{:?}", xor(hash_of_wobble, b"000000000000"));
193+
//println!("{:?}", xor(format!(b"{:?}", hash_of_wobble.unwrap()), format!(b"{:?}",hash_of_weeble.unwrap())));
135194

136-
//let res = xor(b"100f00a00000a000000000fff0000000", b"0000f00000a00000000fff0000000001");
195+
let res = xor(
196+
*b"900f00a00000a000000000fff0000000",
197+
*b"0000f00000a00000000fff0000000001",
198+
);
137199
//println!("\nres={:?}",res);
138200
//let res = xor(b"900f00900090a0900009000900090000", b"1000a0000000000010000fff00000001");
139201
//println!("\nres={:?}",res);
@@ -143,7 +205,13 @@ fn main() -> Result<(), std::io::Error> {
143205
//let res = xor(b"ffffffffffffffffffffffffffffffff", b"10000f00000A00001000f000A00A0001");
144206
//println!("\nres={:?}",res);
145207

146-
//println!("\nxor:{:?}", xor(b"1000000000000000000000000000000f", b"9000000000000000000000000000000f"));
208+
//println!(
209+
// "{:?}",
210+
// xor(
211+
// *b"1000000000000000000000000000000f",
212+
// *b"9000000000000000000000000000000f"
213+
// )
214+
//);
147215
//println!("\nxor:{:?}", xor(b"010000000000000000000000000000f0", b"090000000000000000000000000000f0"));
148216
//println!("\nxor:{:?}", xor(b"00100000000000000000000000000f00", b"00900000000000000000000000000f00"));
149217
//println!("\nxor:{:?}", xor(b"0001000000000000000000000000f000", b"0009000000000000000000000000f000"));
@@ -159,7 +227,13 @@ fn main() -> Result<(), std::io::Error> {
159227
//println!("\nxor:{:?}", xor(b"000000000000010000f0000000000000", b"000000000000090000f0000000000000"));
160228
//println!("\nxor:{:?}", xor(b"00000000000000100f00000000000000", b"00000000000000900f00000000000000"));
161229
//println!("\nxor:{:?}", xor(b"0000000000000001f000000000000000", b"0000000000000009f000000000000000"));
162-
//println!("\nxor:{:?}", xor(b"000000000000000f1000000000000000", b"000000000000000f9000000000000000"));
230+
//println!(
231+
// "{:?}",
232+
// xor(
233+
// *b"000000000000000f1000000000000000",
234+
// *b"000000000000000f9000000000000000"
235+
// )
236+
//);
163237
//println!("\nxor:{:?}", xor(b"00000000000000f00100000000000000", b"00000000000000f00900000000000000"));
164238
//println!("\nxor:{:?}", xor(b"0000000000000f000010000000000000", b"0000000000000f000090000000000000"));
165239
//println!("\nxor:{:?}", xor(b"000000000000f0000001000000000000", b"000000000000f0000009000000000000"));
@@ -174,9 +248,16 @@ fn main() -> Result<(), std::io::Error> {
174248
//println!("\nxor:{:?}", xor(b"000f0000000000000000000000001000", b"000f0000000000000000000000009000"));
175249
//println!("\nxor:{:?}", xor(b"00f00000000000000000000000000100", b"00f00000000000000000000000000900"));
176250
//println!("\nxor:{:?}", xor(b"0f000000000000000000000000000010", b"0f000000000000000000000000000090"));
177-
//println!("\nxor:{:?}", xor(b"f0000000000000000000000000000001", b"f0000000000000000000000000000009"));
251+
//println!(
252+
// "{:?}",
253+
// xor(
254+
// *b"f0000000000000000000000000000001",
255+
// *b"f0000000000000000000000000000009"
256+
// )
257+
//);
178258

179-
let mut sha256_0 = hex::decode(b"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
259+
let mut sha256_0 =
260+
hex::decode(b"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
180261
//for byte in &sha256_0 {
181262
//for byte in &sha256_0 {
182263
for byte in &sha256_0.as_mut() {
@@ -187,16 +268,18 @@ fn main() -> Result<(), std::io::Error> {
187268
//println!("sha256_0.unwrap()=\n{:?}", sha256_0.unwrap());
188269

189270
//for byte in &sha256_0 {
190-
// print!("{:?}",sha256_0.clone().unwrap().pop())
191-
//}
271+
// print!("{:?}",sha256_0.clone().unwrap().pop())
272+
//}
192273

193-
let hexd = hex::decode(b"48656c6c6f20776f726c6421");
274+
//let hexd = hex::decode(b"48656c6c6f20776f726c6421");
194275
//println!("hexd.unwrap()=\n{:?}", hexd.unwrap());
195-
let hello_world = b"Hello world!00000000000000000000";
196-
let hello_worl = b"hello worl!_00000000000000000000";
197-
//println!("hello_world=\n{:?}", hello_world);
198-
//println!("xored\n{:?}", xor(hello_world, hello_worl));
199-
let _ = xor(hello_world, hello_worl);
276+
//let hexd = b"48656c6c6f20776f726c642100000000";
277+
//let hello_world = b"Hello world!00000000000000000000";
278+
//let _ = xor(*hello_world, *hello_world);
279+
//println!("");
280+
//let _ = xor(*hexd, *hello_world);
281+
//println!("");
282+
//let _ = xor(*hexd, *hexd);
200283

201284
let args = Args::parse();
202285
//println!("{args:?}");
@@ -228,27 +311,21 @@ pub fn get_blockheight_string() -> String {
228311
pub fn get_wobble_string() -> String {
229312
format!("{}", wobble().unwrap())
230313
}
231-
pub fn xor<'a>(left: &'a [u8; 32], right: &'a [u8; 32]) -> Vec<&'a u8> {
232-
let mut result = Vec::new();
233-
let mut left_count = left.len();
234-
//println!("{}", left_count);
235-
let right_count = right.len();
236-
//println!("{}", right_count);
314+
pub fn xor<'a>(left: [u8; 32], right: [u8; 32]) -> Vec<u8> {
315+
let mut result: Vec<u8> = Vec::new();
237316
for byte in left {
238317
result.push(byte);
239318
}
240-
for byte in right {
241-
//result.push(byte);
242-
}
319+
let mut count = left.len() - 1;
243320
for byte in &result {
244-
print!("{}", byte);
245-
if left_count > 0 && left_count < right_count {
246-
let _ = (result[left_count] ^ right[left_count]);
247-
left_count -= 1;
248-
}
321+
print!(">>>-->{}<---<<<", byte);
322+
//if count >= 0 && count <= 31 {
323+
result.push(left[count].clone() ^ right[count].clone());
324+
count -= 1;
325+
//}
326+
return result;
249327
}
250-
result
251-
//(left[0] ^ right[0]).into()
328+
Vec::new()
252329
}
253330
pub fn div(left: usize, right: usize) -> usize {
254331
left / right

0 commit comments

Comments
 (0)