Automata Lab Report 1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

1|Page

TOPIC 1: Phone Number Checking


Title: Implementation of a program which read data set from a file and check which of them are
valid phone number.
Objective: To know about phone number checking operating system.
Methodology:

 Take input from a file.


 Checking if the data is started with “+880”.
 Checking the length of the data is 14 or not.
 Checking the fifth position of the data is one or not.
 Checking the sixth position of the data is 3/5/6/7/9 or anything else.
 If the number fulfill above requirements then it’s a valid number, otherwise invalid.

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

29. if(lastpart[i]=='1' || lastpart[i]=='2' || lastpart[i]=='4' || lastpart[i


]=='8')
30. return 0;
31. }
32. else
33. {
34. if(!isdigit(lastpart[i]))
35. {
36. return 0;
37. }
38. }
39. }
40.
41. return 1;
42. }
43.
44. int main()
45. {
46. string buffer;
47. ifstream in;
48. in.open("PhoneList.txt");
49. for(int i=0; i<=12; i++)
50. {
51. in>>buffer;
52. //cout<<buffer<<endl;
53. phone.push_back(buffer);
54. }
55. for(int i=0; i<phone.size(); i++)
56. {
57. int flag;
58. flag=phone_number_automata(phone[i]);
59. if(flag==1)
60. cout<<phone[i]<<"\tValid"<<endl;
61. else
62. cout<<phone[i]<<"\tInvalid"<<endl;
63. }
64. }

Result: Output of the code


1. +8801721664999 Valid
2. +8801521502315 Valid
3. 01721664999 Invalid
4. +8801791373638 Valid
5. +88017913736388 Invalid
6. +8801316104213 Valid
7. 01755627979 Invalid
8. +8801755627979 Valid
9. +8801221664999 Invalid
10. +8801421664999 Invalid
11. +8801521664999 Valid
12. +8801921664999 Valid
13. +8802721664999 Invalid
14.
15. Process returned 0 (0x0) execution time : 0.270 s
16. Press any key to continue.
3|Page

Performance Analysis:

Phone Number Valid or Invalid Result Accuracy


+8801721664999 Number is valid Valid 100%
+8801521502315 Number is valid Valid 100%
01721664999 Invalid because it doesn’t Invalid 100%
start with +880
+8801791373638 Number is valid Valid 100%
+88017913736388 Invalid because length is 15 Invalid 100%
+8801316104213 Number is valid Valid 100%
01755627979 Invalid because it doesn’t Invalid 100%
start with +880
+8801755627979 Number is valid Valid 100%
+8801221664999 Invalid because sixth Invalid 100%
position value is 2
+8801421664999 Invalid because sixth Invalid 100%
position value is 4
+8801521664999 Number is valid Valid 100%
+8801921664999 Number is valid Valid 100%
+8802721664999 Invalid because fifth Invalid 100%
position value is 2
Conclusion and Observation:

This code works according to our algorithm and it can determine whether a number is valid
phone number or not.

TOPIC 2: OTP Generating


Title: We need to generate some OTP using random number generating algorithm which have
“RUET--” string and six random digit and show the output in a file.
Objective: To know about OTP generating method.
Methodology:

 Randomly taking initial value of x, a, c and m.


 Calculate new value of x using the function x= ((a*x)+c)%m
 If length of x is less than six then skip that number.
 Print the output in a file named OTP with “RUET--” string.
Implementation:
I have implemented the algorithm according to above theory. The tools I used here:
 C++
 IDE : Codeblocks
4|Page

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. }

Result: Output of the code


1. [1] RUET-1624663
2. [2] RUET-4621997
3. [3] RUET-1597982
4. [4] RUET-4381868
5. [5] RUET-9436828
6. [6] RUET-4931433
7. [7] RUET-4382906
8. [8] RUET-9446170
9. [9] RUET-5015511
10. [10] RUET-5139608
11. [11] RUET-6256481
12. [12] RUET-6308331
13. [13] RUET-6774981
14. [14] RUET-8773453
15. [15] RUET-8961065

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

You might also like