Automata Lab Report 1
Automata Lab Report 1
Implementation:
I have implemented the algorithm according to above theory. The tools I used here:
C++
IDE : Codeblocks
Source Code:
1. //Source code for checking valid phone number
2. #include<bits/stdc++.h>
3. using namespace std;
4. #include<fstream>
5. vector<string>phone;
6.
7. int phone_number_automata(string s)
8. {
9. string firstpart=s.substr(0,4);
10. string lastpart=s.substr(4,s.size());
11.
12. string chk1="+880";
13. //cout<<firstpart<<endl<<lastpart<<endl;
14.
15. if(firstpart!=chk1)
16. return 0;
17. if(lastpart.size()!=10)
18. return 0;
19.
20. for(int i=0; i<lastpart.size(); i++)
21. {
22. if(i==0)
23. {
24. if(lastpart[i]!='1')
25. return 0;
26. }
27. else if(i==1)
28. {
2|Page
Performance Analysis:
This code works according to our algorithm and it can determine whether a number is valid
phone number or not.
Source Code:
1. //Source code for OTP generation
2. #include<bits/stdc++.h>
3. using namespace std;
4. #include<fstream>
5.
6. int main()
7. {
8. ofstream out;
9. out.open("OTP.txt");
10. int x=243,a=9,c=37,m=10000007,xx,cnt=1;
11. for(int i=1;i<=1000; )
12. {
13. xx=((a*x)+c)%m;
14. if(xx<=999999)
15. {
16. i=i;
17. x=xx;
18. }
19. else
20. {
21. out<<"["<<cnt<<"] "<<"RUET-"<<xx<<endl;
22. cnt=cnt+1;
23. x=xx;
24. i=i+1;
25. }
26. }
27. }
Performance Analysis:
This code generates 1000 OTP. And shows the output in a file. At first, there is OTP number,
then string RUET—and then the random number. Every number’s length is exactly six. So the
code works perfectly.
5|Page