How to find the number of values the equation outputs before repeating the same outputs again?
2 views (last 30 days)
Show older comments
This script is based on implementing Shor's quantum factorization. For the equation 'fncT' whicn is alternative version to mod(), it outputs 4 different values before repeating again, given the parameters 'T = 7' and 'M = 15'. Is it possible to get this number 4 using the fft function and assign it to a variable instead of manually assigning it?
script:
T = 7; % T^P mod(M)
M = 15;
P1 = 127; % 128
P2 = 255; % 258
P3 = 511; % 512
P4 = 1023; % 1024 bits
t = 1:1:sym(P1); % Signal duration/length
fncT = (T.^t) - floor(T.^t/M)*M;
%plot(t,fncT)
%stem(fncT)
A = fftshift(double(fncT));
A = fft(A);
A = fftshift(A);
A_mag = abs(A.*A);
stem(A_mag)
%plot(A_mag);
% GCD
eqn = T^(4/2) + 1; % 4 = no. of time it produces different values before repeating again
eqn1 = T^(4/2) - 1;
[G1] = gcd(eqn,M);
[G2] = gcd(eqn1,M);
disp(['The factors of 15 are ',num2str(G1),' and ', num2str(G2), '.'])
[pks1,pks2,pks3] = findpeaks(A_mag);
x = pks2(1); % Assigning the peaks with a variable
y = pks2(2);
z = pks2(3);
0 Comments
Answers (0)
See Also
Categories
Find more on Spline Postprocessing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!