decrypt_vigenere.m

来自「loading a text file from a directory to 」· M 代码 · 共 48 行

M
48
字号
%% Coincidence Counting Programclose all;clear all;clc;%% Read the cyphered text from a *.txt filetext_input = loadtext('Decrypt_3.txt');%% Remove the blanks from input text.index = find(text_input ~= ' ');text = text_input(index);%% len = length(text);shmax = len-1;count=0;results = zeros(shmax,3);for m=1:shmax        % Rotate text relative to itself by m spots    teststr=[text(m+1:end) text(1:m)];        % Count number of matches    for i=1:len        if teststr(i)==text(i)            count=count+1;        end    end        results(m,1) = m;    results(m,2) = count;        % Normalize the count by the length of the string    results(m,3) = count/len;        % Reset count for next iteration    count=0;end% What does this do?  Try to make sense of it!resultsmax_m=find(max(results(:,3))==results(:,3))max_norm_count=max(results(:,3))f=find(results(:,2)>19);results(f,:)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?