Нужна помощь в Matlab
Вложений: 1
Расшифруйте закон, зашифрованный в следующей строке:
s = '/ b_t3{$ H~MO 6JTQI> Зашифруйте текст , содержащийся в файле gettysburg .txt , и текст самой функции encrypt.m. :tehnari_ru_837::tehnari_ru_837::tehnari_ru_837: Функция encrypt: function encrypt(filein,fileout) %ENCRYPT Apply the CRYPTO function to a text file. % ENCRYPT % with no arguments prompts for a input file name. % ENCRYPT inputfilename % encrypts the text in the input file and displays the results. % ENCRYPT inputfilename outputfilename % stores the encrypted text in the output file. % See also CRYPTO. % Copyright 2012 Cleve Moler and The MathWorks, Inc. if nargin < 1 filein = input('Input file = ','s'); end fin = fopen(filein); if nargin == 2 fout = fopen(fileout,'w'); else fout = 1; end while ~feof(fin) s = fgetl(fin); t = crypto(s); fprintf(fout,'%s\n',t); end fclose all; Функция crypto: function y = crypto(x) % CRYPTO Cryptography example. % y = crypto(x) converts an ASCII text string into another, coded string. % The function is its own inverse, so crypto(crypto(x)) gives x back. % See also: ENCRYPT. % Copyright 2012 Cleve Moler and The MathWorks, Inc. % Use a two-character Hill cipher with arithmetic modulo 97, a prime. p = 97; % Choose two characters above ASCII 128 to expand set from 95 to 97. c1 = char(169); c2 = char(174); x(x==c1) = 127; x(x==c2) = 128; % Convert to integers mod p. x = mod(real(x-32),p); % Reshape into a matrix with 2 rows and floor(length(x)/2) columns. n = 2*floor(length(x)/2); X = reshape(x(1:n),2,n/2); % Encode with matrix multiplication modulo p. A = [71 2; 2 26]; Y = mod(A*X,p); % Reshape into a single row. y = reshape(Y,1,n); % If length(x) is odd, encode the last character. if length(x) > n y(n+1) = mod((p-1)*x(n+1),p); end % Convert to ASCII characters. y = char(y+32); y(y==127) = c1; y(y==128) = c2; |
Часовой пояс GMT +4, время: 08:39. |
Powered by vBulletin® Version 4.5.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.