양자 이미지 암호화 기법과 MATLAB 적용 사례

양자 이미지 표현 기초

향상된 양자 표현(Enhanced Quantum Representation)

function q_img = eqr_encode(input_img)
    [height, width] = size(input_img);
    total_qubits = ceil(log2(height)) + ceil(log2(width)) + 8;
    q_img = zeros(2^total_qubits, 1);
    
    for row = 1:height
        for col = 1:width
            y_bin = dec2bin(row-1, ceil(log2(height)));
            x_bin = dec2bin(col-1, ceil(log2(width)));
            pixel_val = dec2bin(input_img(row,col), 8);
            
            index = bin2dec([y_bin x_bin]) * 256 + bin2dec(pixel_val);
            q_img(index + 1) = 1;
        end
    end
end

기본 양자 암호화 알고리즘

양자 아놀드 변환 기반 암호화

function enc_img = q_arnold_encrypt(input_img, iter_count)
    [height, width] = size(input_img);
    enc_img = zeros(height, width);
    transform_mat = [1, 1; 1, 2];
    
    for cnt = 1:iter_count
        for r = 1:height
            for c = 1:width
                orig_pos = [r-1; c-1];
                new_pos = mod(transform_mat * orig_pos, [height; width]);
                enc_img(new_pos(1)+1, new_pos(2)+1) = input_img(r, c);
            end
        end
        input_img = enc_img;
    end
end

양자 비트 평면 암호화

function [enc_img, perm_key] = q_bit_encrypt(img)
    [h, w] = size(img);
    bit_layers = zeros(h, w, 8);
    
    for layer = 1:8
        bit_layers(:,:,layer) = bitget(img, layer);
    end
    
    perm_key = randperm(8);
    shuffled_layers = bit_layers(:,:,perm_key);
    
    enc_img = zeros(h, w);
    for k = 1:8
        enc_img = enc_img + shuffled_layers(:,:,k) * 2^(k-1);
    end
end

양자 카오스 시스템 암호화

function [enc_img, key_seq] = q_chaos_encrypt(img, init_val, param, skip)
    [h, w] = size(img);
    pixel_count = h * w;
    chaos_seq = zeros(1, pixel_count + skip);
    chaos_seq(1) = init_val;
    
    for i = 2:(pixel_count + skip)
        chaos_seq(i) = param * chaos_seq(i-1) * (1 - chaos_seq(i-1));
    end
    
    key_seq = chaos_seq(skip+1:end);
    img_vec = img(:);
    enc_data = zeros(pixel_count, 1);
    
    for idx = 1:pixel_count
        key_byte = mod(floor(key_seq(idx) * 1e10), 256);
        enc_data(idx) = bitxor(uint8(img_vec(idx)), uint8(key_byte));
    end
    
    enc_img = reshape(enc_data, h, w);
end

통합 암호화 시스템

function [enc_img, enc_keys] = qimg_encrypt_system(img, method)
    switch method
        case 'Arnold'
            enc_img = q_arnold_encrypt(img, 10);
            enc_keys.iterations = 10;
            
        case 'BitPlane'
            [enc_img, enc_keys.perm_key] = q_bit_encrypt(img);
            
        case 'Chaos'
            [enc_img, enc_keys] = q_chaos_encrypt(img, 0.3, 3.99, 1000);
            
        case 'Hybrid'
            [temp_img, k1] = q_bit_encrypt(img);
            temp_img = q_arnold_encrypt(temp_img, 5);
            [enc_img, k2] = q_chaos_encrypt(temp_img, 0.3, 3.99, 1000);
            enc_keys = struct('bit_key', k1, 'chaos_keys', k2);
    end
end

복호화 예시

function dec_img = q_arnold_decrypt(enc_img, iter_count)
    [h, w] = size(enc_img);
    dec_img = zeros(h, w);
    inv_matrix = [2, -1; -1, 1];
    
    for cnt = 1:iter_count
        for r = 1:h
            for c = 1:w
                pos = [r-1; c-1];
                orig_pos = mod(inv_matrix * pos, [h; w]);
                dec_img(orig_pos(1)+1, orig_pos(2)+1) = enc_img(r, c);
            end
        end
        enc_img = dec_img;
    end
end

성능 평가 방법

img = imread('cameraman.tif');
enc_img = qimg_encrypt_system(img, 'Hybrid');

mse = mean((double(img(:)) - double(enc_img(:))).^2);
psnr = 10 * log10(255^2 / mse);

horiz_corr = corrcoef(double(img(1:end-1,:)), double(img(2:end,:)));
vert_corr = corrcoef(double(img(:,1:end-1)), double(img(:,2:end)));

FRQI 양자 표현

function q_state = frqi_encode(norm_img)
    [h, w] = size(norm_img);
    n_qubits = ceil(log2(h * w));
    q_state = zeros(2^n_qubits, 1);
    
    total_prob = 0;
    for i = 1:h
        for j = 1:w
            idx = (i-1)*w + j;
            if idx <= length(q_state)
                angle = acos(norm_img(i,j));
                q_state(idx) = exp(1i * angle);
                total_prob = total_prob + abs(q_state(idx))^2;
            end
        end
    end
    q_state = q_state / sqrt(total_prob);
end

중요 고려사항

  • 모든 구현은 양자 연산을 고전적으로 모사한 것임
  • 실제 양자 하드웨어에서는 다른 접근 방식 필요
  • 이미지 크기는 2n × 2m 형태 권장
  • 실제 양자 암호화에는 Hadamard, CNOT 게이트 적용 필요

태그: 양자암호 이미지보안 MATLAB프로그래밍 양자컴퓨팅 암호화알고리즘

6월 12일 20:32에 게시됨