Print out all HTML tags in file in Lex
INPUT :-
tags.txt
OUTPUT
Coding Blocks in Python, C/C++, Java, and other popular programming languages with our easy to follow tutorials, examples, Easy Program in Languages. Coding Blocks is a tutorials site for beginners that covers topics like Java, AWT, JSP, Servlet, JSTL, C, C++, DBMS, Perl, WordPress, SEO. A popular programming and development in blog. Here you can learn C, C++, Java, Python, Android Development, PHP, SQL, JavaScript, .Net, etc. C Programming, C++ Programming, Java Programming, Python Programming.
INPUT :-
tags.txt
OUTPUT
Num.l
INPUT :-
num.txt
OUTPUT
Method
| Description |
onCreate | called when activity is first created.
|
onStart
| called when activity is becoming visible to the user. |
onResume | called when activity will start interacting with the user. |
onPause | called when activity is not visible to the user. |
onStop | called when activity is no longer visible to the user. |
onRestart | called after your activity is stopped, prior to start. |
onDestroy | called before the activity is destroyed. |
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Android Life Cycle Program!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
package com.example.sunny.lifecycle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.makeText(getApplicationContext(),"onCreate Method Call",
Toast.LENGTH_LONG).show();
}
protected void onStart()
{
super.onStart();
Toast.makeText(getApplicationContext(),"onStart Method Call",
Toast.LENGTH_LONG).show();
}
@Override
protected void onRestart()
{
super.onRestart();
Toast.makeText(getApplicationContext(),"onRestart Method Call",
Toast.LENGTH_LONG).show();
}
protected void onPause()
{
super.onPause();
Toast.makeText(getApplicationContext(),"onPause Method Call",
Toast.LENGTH_LONG).show();
}
protected void onResume()
{
super.onResume();
Toast.makeText(getApplicationContext(),"onResume Method Call",
Toast.LENGTH_LONG).show();
}
protected void onStop()
{
super.onStop();
Toast.makeText(getApplicationContext(),"onStop Method Call",
Toast.LENGTH_LONG).show();
}
protected void onDestroy()
{
super.onDestroy();
Toast.makeText(getApplicationContext(),"onDestroy Method Call",
Toast.LENGTH_LONG).show();
}
}
Count no of characters no. of lines & no. of words in Lex Program.
Step 1 :- lex filename.l or lex filename.lex depending on the extension file is saved with
Step 2 :- gcc lex.yy.c
Step 3 :- ./a.out
file.l
INPUT :
s.txt
OUTPUT
import math
print("RSA ENCRYPTION/DECRYPTION")
print("*****************************************************")
# Input Prime Numbers
print("PLEASE ENTER THE 'x' AND 'y' VALUES BELOW:")
x = int(input("Enter a prime number for x: "))
y = int(input("Enter a prime number for y: "))
print("*****************************************************")
def prime_check(k):
if (k == 2):
return True
elif ((k < 2) or ((k % 2) == 0)):
return False
elif (k > 2):
for i in range(2, k):
if not (k % i):
return false
return True
check_x = prime_check(x)
check_y = prime_check(y)
while (((check_x == False) or (check_y == False))):
x = int(input("Enter a prime number for x: "))
y = int(input("Enter a prime number for y: "))
check_x = prime_check(x)
check_y = prime_check(y)
n = x * y
print("RSA Modulus(n) is:", n)
r = (x - 1) * (y - 1)
print("Eulers Toitent(r) is:", r)
print("*****************************************************")
def egcd(e, r):
while (r != 0):
e, r = r, e % r
return e
def eugcd(e, r):
for i in range(1, r):
while (e != 0):
a, b = r // e, r % e
if (b != 0):
print("%d = %d*(%d) + %d" % (r, a, e, b))
r = e
e = b
def eea(a, b):
if (a % b == 0):
return (b, 0, 1)
else:
gcd, s, t = eea(b, a % b)
s = s - ((a // b) * t)
print("%d = %d*(%d) + (%d)*(%d)" % (gcd, a, t, s, b))
return (gcd, t, s)
def mult_inv(e, r):
gcd, s, _ = eea(e, r)
if (gcd != 1):
return None
else:
if (s < 0):
print("s=%d. Since %d is less than 0, "
"s = s(modr), i.e., s=%d." % (s, s, s % r))
elif (s > 0):
print("s=%d." % (s))
return s % r
for i in range(1, 1000):
if (egcd(i, r) == 1):
e = i
print("The value of e is:", e)
print("*****************************************************")
print("RSA ALGORITHM:")
eugcd(e, r)
print("END OF THE STEPS USED TO ACHIEVE EUCLID'S ALGORITHM.")
print("*****************************************************")
print("RSA EXTENDED ALGORITHM:")
d = mult_inv(e, r)
print("END OF THE STEPS USED TO ACHIEVE THE VALUE OF 'd'.")
print("The value of d is:", d)
print("*****************************************************")
public = (e, n)
private = (d, n)
print("Private Key is:", private)
print("Public Key is:", public)
print("*****************************************************")
def encrypt(pub_key, n_text):
e, n = pub_key
x = []
m = 0
for i in n_text:
if (i.isupper()):
m = ord(i) - 65
c = (m ** e) % n
x.append(c)
elif (i.islower()):
m = ord(i) - 97
c = (m ** e) % n
x.append(c)
elif (i.isspace()):
spc = 500
x.append(500)
return x
def decrypt(priv_key, c_text):
d, n = priv_key
txt = c_text.split(',')
x = ''
m = 0
for i in txt:
if (i == '500'):
x += ' '
else:
m = (int(i) ** d) % n
m += 65
c = chr(m)
x += c
return x
message = input("You like Encrypted or Decrypted?(Separate numbers with ',' for Decryption):")print("Your Message is ::", message)
choose = input("Type '1' for Encryption and '2' for Decryption.")
if (choose == '1'):
enc_msg = encrypt(public, message)
print("Your Encrypted Message is:", enc_msg)
print("Thank you for using the RSA Encryption Algorithm. Goodbye!")
elif (choose == '2'):
print("Your Decrypted Message is:", decrypt(private, message))
print("Thank you for using the RSA Encryption Algorithm. Goodbye!")
else:
print("You entered the wrong option.")
print("Thank you for using the RSA Encryption Algorithm. Goodbye!")
RSA ENCRYPTION/DECRYPTION
*****************************************************
PLEASE ENTER THE 'x' AND 'y' VALUES BELOW:
Enter a prime number for x: 3
Enter a prime number for y: 5
*****************************************************
RSA Modulus(n) is: 15
Eulers Toitent(r) is: 8
*****************************************************
The value of e is: 999
*****************************************************
RSA ALGORITHM:
8 = 0*(999) + 8
999 = 124*(8) + 7
8 = 1*(7) + 1
END OF THE STEPS USED TO ACHIEVE EUCLID'S ALGORITHM.
*****************************************************
RSA EXTENDED ALGORITHM:
1 = 8*(1) + (-1)*(7)
1 = 999*(-1) + (125)*(8)
s=-1. Since -1 is less than 0, s = s(modr), i.e., s=7.
END OF THE STEPS USED TO ACHIEVE THE VALUE OF 'd'.
The value of d is: 7
*****************************************************
Private Key is: (7, 15)
Public Key is: (999, 15)
*****************************************************
You like Encrypted or Decrypted? (Separate numbers with ',' for Decryption):3,15,20,17,13
Your Message is :: 3,15,20,17,13
Type '1' for Encryption and '2' for Decryption.2
Your Decrypted Message is: MAFIH
Thank you for using the RSA Encryption Algorithm. Goodbye!