stage
This commit is contained in:
8
problems/p1/Cargo.toml
Normal file
8
problems/p1/Cargo.toml
Normal file
@@ -0,0 +1,8 @@
|
||||
[package]
|
||||
name = "p1"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
hex = "0.4.3"
|
||||
base64 = "0.22.1"
|
||||
13
problems/p1/src/main.rs
Normal file
13
problems/p1/src/main.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
use base64::{Engine as _, engine::general_purpose::STANDARD};
|
||||
|
||||
fn hex_to_base64(hex_str: &str) -> String {
|
||||
let bytes = hex::decode(hex_str).expect("解码失败");
|
||||
STANDARD.encode(&bytes)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// 从十六进制字符串解码为原始字节
|
||||
let hex_str = "49276d206b696c6c696e6720796f757220627261696e206c696b65206120706f69736f6e6f7573206d757368726f6f6d";
|
||||
let base64_str = hex_to_base64(hex_str);
|
||||
println!("十六进制字符串: {}", base64_str);
|
||||
}
|
||||
Reference in New Issue
Block a user