#walkzzz/image.mbt/process/encryption

    图像加密与解密(XOR、Arnold、混沌、LSB 水印)

    #概览

    项目数量
    公开函数29
    公开类型10
    常量0
    错误类型0

    #类型

    pub(all) struct ArnoldParams {
    pub(all) struct ChaoticParams {
    pub(all) enum EncryptionAlgorithm {
    pub(all) struct EncryptionConfig {
    pub(all) struct EncryptionQuality {
    pub(all) struct EncryptionResult {
    pub(all) struct ImageEncryptionQuality {
    pub(all) struct WatermarkExtractionResult {
    pub(all) struct WatermarkInfo {
    pub(all) enum WatermarkType {

    #API

    pub fn adjacent_correlation(@types.Image, direction? : String) -> Double raise @types.LoadError
    pub fn arnold_scramble(@types.Image, ArnoldParams) -> EncryptionResult raise @types.LoadError
    pub fn batch_encrypt(Array[@types.Image], Double) -> Array[@types.Image] raise @types.LoadError
    pub fn calculate_correlation(@types.Image, @types.Image) -> Double raise @types.LoadError
    pub fn calculate_image_entropy(@types.Image) -> Double raise @types.LoadError
    pub fn calculate_psnr(@types.Image, @types.Image) -> Double raise @types.LoadError
    pub fn chaotic_encrypt(@types.Image, ChaoticParams) -> EncryptionResult raise @types.LoadError
    pub fn create_default_arnold_params() -> ArnoldParams
    pub fn create_default_chaotic_params() -> ChaoticParams
    pub fn decrypt_image_logistic(@types.Image, key? : Double, mu? : Double) -> @types.Image raise @types.LoadError
    pub fn decrypt_image_xor(@types.Image, String) -> @types.Image raise @types.LoadError
    pub fn embed_visible_watermark(@types.Image, String, Int, Int, Double) -> @types.Image raise @types.LoadError
    pub fn embed_watermark_lsb(@types.Image, Array[Byte], Int) -> (@types.Image, WatermarkInfo) raise @types.LoadError
    pub fn encrypt_image_logistic(@types.Image, key? : Double, mu? : Double) -> @types.Image raise @types.LoadError
    pub fn encrypt_image_xor(@types.Image, String) -> @types.Image raise @types.LoadError
    pub fn encryption_default_config() -> EncryptionConfig
    pub fn encryption_report_to_string(EncryptionResult, WatermarkInfo, ImageEncryptionQuality) -> String
    pub fn evaluate_encryption_quality(@types.Image, @types.Image) -> EncryptionQuality raise @types.LoadError
    pub fn evaluate_image_encryption_quality(@types.Image, @types.Image) -> ImageEncryptionQuality raise @types.LoadError
    pub fn extract_watermark_lsb(@types.Image, Int, Int) -> WatermarkExtractionResult raise @types.LoadError
    pub fn generate_chaotic_sequence_enc(ChaoticParams, Int) -> Array[Double]
    pub fn histogram_entropy(@types.Image) -> Double raise @types.LoadError
    pub fn key_sensitivity_test(@types.Image, Double, delta? : Double) -> Double raise @types.LoadError
    pub fn xor_decrypt(EncryptionResult, Array[Byte]) -> @types.Image
    pub fn xor_encrypt(@types.Image, Array[Byte]) -> EncryptionResult raise @types.LoadError
    pub fn EncryptionAlgorithm::equal(Self, Self) -> Bool
    pub fn EncryptionAlgorithm::not_equal(Self, Self) -> Bool
    pub fn WatermarkType::equal(Self, Self) -> Bool
    pub fn WatermarkType::not_equal(Self, Self) -> Bool

    #纯 MoonBit 实现

    本包不依赖任何 C FFI,四目标(native/wasm-gc/js/wasm)均可编译运行。

    ArnoldParams

    pub(all) struct ArnoldParams {
    iterations : Int
    a : Int
    b : Int
    }

    Arnold 置乱参数

    ChaoticParams

    pub(all) struct ChaoticParams {
    x0 : Double
    y0 : Double
    z0 : Double
    a : Double
    b : Double
    c : Double
    iterations : Int
    }

    混沌系统参数

    EncryptionAlgorithm

    pub(all) enum EncryptionAlgorithm {
    XOR
    AES_Simplified
    Chaotic
    Arnold
    Hill
    RSA_Simplified
    Unknown
    } derive(Eq)

    加密算法类型 #non_exhaustive 表示未来可能添加新构造器

    EncryptionAlgorithm::equal

    automatically derived

    EncryptionAlgorithm::not_equal

    automatically derived

    EncryptionConfig

    pub(all) struct EncryptionConfig {
    method_type : String
    key : Double
    mu : Double
    iterations : Int
    }

    加密配置

    EncryptionQuality

    pub(all) struct EncryptionQuality {
    entropy : Double
    correlation_h : Double
    correlation_v : Double
    correlation_d : Double
    npcr : Double
    uaci : Double
    }

    加密质量评估

    EncryptionResult

    pub(all) struct EncryptionResult {
    encrypted_data : Array[Byte]
    width : Int
    height : Int
    channels : Int
    algorithm : EncryptionAlgorithm
    key_hash : String
    encryption_time_ms : Double
    file_size_original : Int
    file_size_encrypted : Int
    }

    加密结果

    ImageEncryptionQuality

    pub(all) struct ImageEncryptionQuality {
    entropy : Double
    correlation_horizontal : Double
    correlation_vertical : Double
    correlation_diagonal : Double
    uaci : Double
    npcr : Double
    key_sensitivity : Double
    psnr : Double
    } derive(Default, Eq,
    Debug
    )

    加密质量评估

    ImageEncryptionQuality::default

    automatically derived

    ImageEncryptionQuality::equal

    automatically derived

    ImageEncryptionQuality::not_equal

    automatically derived

    ImageEncryptionQuality::to_repr

    automatically derived

    WatermarkExtractionResult

    pub(all) struct WatermarkExtractionResult {
    watermark_data : Array[Byte]
    watermark_width : Int
    watermark_height : Int
    similarity : Double
    extracted : Bool
    extraction_time_ms : Double
    }

    水印提取结果

    WatermarkInfo

    pub(all) struct WatermarkInfo {
    watermark_type : WatermarkType
    watermark_data : Array[Byte]
    watermark_width : Int
    watermark_height : Int
    strength : Double
    embedded : Bool
    embedding_position : String
    key : String
    }

    水印信息

    WatermarkType

    pub(all) enum WatermarkType {
    Visible
    Invisible_LSB
    Invisible_DCT
    Invisible_DWT
    Robust
    Fragile
    Unknown
    } derive(Eq)

    水印类型 #non_exhaustive 表示未来可能添加新构造器

    WatermarkType::equal

    automatically derived

    WatermarkType::not_equal

    fn WatermarkType::not_equal(x : WatermarkType, y : WatermarkType) -> Bool
    automatically derived

    adjacent_correlation

    fn adjacent_correlation(img :
    core
    /types.Image, direction? : String) -> Double raise
    core
    /types.LoadError

    计算相邻像素相关性(加密后应接近 0)

    arnold_scramble

    fn arnold_scramble(img :
    core
    /types.Image, params : ArnoldParams) -> EncryptionResult raise
    core
    /types.LoadError

    Arnold 置乱加密

    batch_encrypt

    fn batch_encrypt(images : Array[
    core
    /types.Image], key : Double) -> Array[
    core
    /types.Image] raise
    core
    /types.LoadError

    批量加密

    calculate_correlation

    fn calculate_correlation(img1 :
    core
    /types.Image, img2 :
    core
    /types.Image) -> Double raise
    core
    /types.LoadError

    计算相邻像素相关性

    calculate_image_entropy

    fn calculate_image_entropy(img :
    core
    /types.Image) -> Double raise
    core
    /types.LoadError

    计算图像熵

    calculate_psnr

    fn calculate_psnr(original :
    core
    /types.Image, encrypted :
    core
    /types.Image) -> Double raise
    core
    /types.LoadError

    计算 PSNR(峰值信噪比)

    chaotic_encrypt

    fn chaotic_encrypt(img :
    core
    /types.Image, params : ChaoticParams) -> EncryptionResult raise
    core
    /types.LoadError

    混沌加密

    create_default_arnold_params

    fn create_default_arnold_params() -> ArnoldParams

    创建默认 Arnold 参数

    create_default_chaotic_params

    fn create_default_chaotic_params() -> ChaoticParams

    创建默认混沌参数

    decrypt_image_logistic

    fn decrypt_image_logistic(img :
    core
    /types.Image, key? : Double, mu? : Double) ->
    core
    /types.Image raise
    core
    /types.LoadError

    基于 Logistic 混沌映射的图像解密(与加密相同,因为 XOR 是对称的)

    decrypt_image_xor

    fn decrypt_image_xor(img :
    core
    /types.Image, key : String) ->
    core
    /types.Image raise
    core
    /types.LoadError

    简单的 XOR 解密

    embed_visible_watermark

    fn embed_visible_watermark(img :
    core
    /types.Image, watermark_text : String, x : Int, y : Int, opacity : Double) ->
    core
    /types.Image raise
    core
    /types.LoadError

    可见水印嵌入

    embed_watermark_lsb

    fn embed_watermark_lsb(img :
    core
    /types.Image, watermark : Array[Byte], strength : Int) -> (
    core
    /types.Image, WatermarkInfo) raise
    core
    /types.LoadError

    LSB 水印嵌入

    encrypt_image_logistic

    fn encrypt_image_logistic(img :
    core
    /types.Image, key? : Double, mu? : Double) ->
    core
    /types.Image raise
    core
    /types.LoadError

    基于 Logistic 混沌映射的图像加密

    encrypt_image_xor

    fn encrypt_image_xor(img :
    core
    /types.Image, key : String) ->
    core
    /types.Image raise
    core
    /types.LoadError

    简单的 XOR 加密(使用密钥字节序列)

    encryption_default_config

    fn encryption_default_config() -> EncryptionConfig

    创建默认加密配置

    encryption_report_to_string

    fn encryption_report_to_string(encryption : EncryptionResult, watermark : WatermarkInfo, quality : ImageEncryptionQuality) -> String

    生成加密与水印报告

    evaluate_encryption_quality

    fn evaluate_encryption_quality(original :
    core
    /types.Image, encrypted :
    core
    /types.Image) -> EncryptionQuality raise
    core
    /types.LoadError

    评估加密质量

    evaluate_image_encryption_quality

    fn evaluate_image_encryption_quality(original :
    core
    /types.Image, encrypted :
    core
    /types.Image) -> ImageEncryptionQuality raise
    core
    /types.LoadError

    评估加密质量

    extract_watermark_lsb

    fn extract_watermark_lsb(img :
    core
    /types.Image, watermark_length : Int, strength : Int) -> WatermarkExtractionResult raise
    core
    /types.LoadError

    LSB 水印提取

    generate_chaotic_sequence_enc

    fn generate_chaotic_sequence_enc(params : ChaoticParams, length : Int) -> Array[Double]

    生成混沌序列(Lorenz 系统简化版)

    histogram_entropy

    fn histogram_entropy(img :
    core
    /types.Image) -> Double raise
    core
    /types.LoadError

    计算直方图熵(衡量加密质量,熵越高越好)

    key_sensitivity_test

    fn key_sensitivity_test(img :
    core
    /types.Image, key : Double, delta? : Double) -> Double raise
    core
    /types.LoadError

    密钥敏感性测试(微小密钥变化导致完全不同的密文)

    xor_decrypt

    fn xor_decrypt(encrypted : EncryptionResult, key : Array[Byte]) ->
    core
    /types.Image

    XOR 解密

    xor_encrypt

    fn xor_encrypt(img :
    core
    /types.Image, key : Array[Byte]) -> EncryptionResult raise
    core
    /types.LoadError

    XOR 加密