report on ai
DESCRIPTION
ARTIFICIAL INTELLIGENCETRANSCRIPT
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 1/25
Q. Write a program in C to implement Caesar Cipher algorithm.
#include <stdio.h>
int main()
{ char string4[80!
int rotator"!
print($%nter &tring' $)!
gets(string4)!
print($%nter "umer' $)!
scan($i$* +rotator")!
int n , 0* rotate&-ap , 0!
int i!
or(i,0! string4[i , /0/! i11)
{ i(string4[i >,/a/ ++ string4[i
<,/2/){ n , /2/ 3 string4[i!
i( rotator" > n )
{ rotate&-ap , rotator" 3 n3 ! string4[i , /a/!string4[i 1, rotate&-ap!
5else
string4[i 1, rotator"!
55
int 6!or(6 , 0! string4[6 ,/0/! 611)
{5 print($c$* string4[6)!
7ai 9erma (:04;;0:)
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 2/25
print($n$)!
return 0!
5
7ai 9erma (:04;;0:)
:
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 3/25
=utput'
7ai 9erma (:04;;0:)
;
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 4/25
Q. Write a program to implement %& algorithm.
pac?age aes!
import [email protected]!
import 6aa.util.rra@s!
import [email protected]@Eenerator!
import 6aa.cr@pto.&ecretDe@!
import [email protected].&ecretDe@&pec!
import [email protected]&pec!
import [email protected]!
import [email protected]&pec!
import [email protected].&ecretDe@&pec!
pulic class es {
static &tring F9 , $$!
static &tring plaintet , $test tet :;000$! HI"ote null
paddingIH static &tring encr@ptionDe@ , $0:;4JK8Lacde$!
pulic static oid main(&tring[
args) { tr@ {
&@stem.out.println($%&$)!
&@stem.out.println($plain' $ 1 plaintet)!
@te[ cipher , encr@pt(plaintet* encr@ptionDe@)!
&@stem.out.print($cipher' $)!
or (int i , 0! i < cipher.length! i11) {
7ai 9erma (:04;;0:)
4
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 5/25
&@stem.out.print(ne- Fnteger(cipher[i) 1 $ $)!
5
&@stem.out.println($$)!
&tring decr@pted , decr@pt(cipher* encr@ptionDe@)!
&@stem.out.println($decr@pt' $ 1 decr@pted)!
5 catch (%ception e)
{ e.print&tac?Mrace(
)!
5
5
pulic static @te[ encr@pt(&tring plainMet* &tring encr@ptionDe@) thro-s %ception
{ Cipher cipher , Cipher.getFnstance($%&HCNCH"oGadding$* $&unOC%$)!
&ecretDe@&pec ?e@ , ne- &ecretDe@&pec(encr@[email protected]@tes($PM38$)* $%&$)!
cipher.init(Cipher.%"C7RGMSA=B%* ?e@* ne- FGarameter&pec(F9.getN@tes($PM3
8$)))! return cipher.doinal(plainMet.getN@tes($PM38$))!
5
pulic static &tring decr@pt(@te[ cipherMet* &tring encr@ptionDe@) thro-s %ception
{ Cipher cipher , Cipher.getFnstance($%&HCNCH"oGadding$* $&unOC%$)!
&ecretDe@&pec ?e@ , ne- &ecretDe@&pec(encr@[email protected]@tes($PM38$)* $%&$)!
cipher.init(Cipher.B%C7RGMSA=B%* ?e@* ne- FGarameter&pec(F9.getN@tes($PM3
8$)))! return ne- &tring(cipher.doinal(cipherMet)* $PM38$)!
5
5
7ai 9erma (:04;;0:)
J
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 6/25
=utput'
7ai 9erma (:04;;0:)
K
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 7/25
Q. Write a program to implement %uclidTs algorithm.
#include <stdio.h>
int greatestCommonBiisor(int m* int n)
{
int r*true!
i((m ,, 0) UU (n ,,
0)) return 0!
else i((m < 0) UU (n <
0)) return 3!
do
{
r , m
n! i(r ,,
0) rea?!
m , n!
n , r!
5
-hile(true)!
return n!
5
int main(oid)
{
int num*num:!
print($n enter t-o numers n$)!
scan($dd$*+num*+num:)!
7ai 9erma (:04;;0:)
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 8/25
int gcd , greatestCommonBiisor(num* num:)!
print($Mhe ECB o d and d is dn$* num* num:* gcd)!
getchar()!
return 0!
5
7ai 9erma (:04;;0:)
8
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 9/25
=utput'
7ai 9erma (:04;;0:)
L
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 10/25
Q. Write a program to implement %tended %uclid algorithm.
pac?age etendedeuclid!
import 6aa.util.&canner!
HII Class %tended%uclid IIH
pulic class %tended%uclid
{
HII unction to sole IIH
pulic oid sole(long a* long )
{
long , 0* @ , * last , * last@ , 0*
temp! -hile ( , 0)
{
long V , a H !
long r , a !
a , !
, r!
temp , !
, last 3 V I !
last , temp!
temp , @!
@ , last@ 3 V I @!
last@ , temp!
7ai 9erma (:04;;0:)
0
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 11/25
5
&@stem.out.println($7oots ' $1 last 1$ @ '$1 last@)!
5
HII Aain unction IIH
pulic static oid main (&tring[ args)
{
&canner scan , ne- &canner(&@stem.in)!
&@stem.out.println($%tended %uclid lgorithm
Mestn$)! HII Aa?e an o6ect o %tended%uclid class
IIH %tended%uclid ee , ne- %tended%uclid()!
HII ccept t-o integers IIH
&@stem.out.println($%nter a o a 1 @ , gcd(a*
)n$)! long a , scan.netong()!
long , scan.netong()!
HII Call unction sole o class
%tended%uclid IIH ee.sole(a* )!
5
5
7ai 9erma (:04;;0:)
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 12/25
=utput'
7ai 9erma (:04;;0:)
:
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 13/25
Q. Write a program to implement 7ain Ailler Grimalit@ Mest
#include <iostream>
#include <cstring>
#include <cstdli>
#deine ll long long
using namespace std!
HI
I calculates (a I ) c ta?ing into account that a I might
oerlo- IH
ll mulmod(ll a* ll * ll mod)
{
ll , 0*@ , a
mod! -hile ( > 0)
{
i ( : ,, )
{
, ( 1 @) mod!
5
@ , (@ I :)
mod! H, :!
5
return mod!
5 HI
I modular
eponentiation IH
7ai 9erma (:04;;0:)
;
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 14/25
ll modulo(ll ase* ll eponent* ll mod)
{
ll , !
ll @ , ase!
-hile (eponent > 0)
{
i (eponent : ,, )
, ( I @) mod!
@ , (@ I @) mod!
eponent , eponent H :!
5
return mod!
5
HI
I Ailler37ain primalit@ test* iteration signiies the
accurac@ IH
ool Ailler(ll p*int iteration)
{
i (p < :)
{
return alse!
5
i (p , : ++ p :,,0)
{
return alse!
5
7ai 9erma (:04;;0:)
4
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 15/25
ll s , p 3 !
-hile (s : ,, 0)
{
s H, :!
5
or (int i , 0! i < iteration! i11)
{
ll a , rand() (p 3 ) 1 * temp ,
s! ll mod , modulo(a* temp* p)!
-hile (temp , p 3 ++ mod , ++ mod , p 3 )
{
mod , mulmod(mod*
mod* p)! temp I, :!
5
i (mod , p 3 ++ temp : ,, 0)
{
return alse!
5
5
return true!
5
HHAain int
main()
{
int iteration ,
J! ll num!
cout<<$%nter integer to test primalit@' $!
7ai 9erma (:04;;0:)
J
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 16/25
cin>>num!
i (Ailler(num* iteration))
cout<<num<<$ is prime$<<endl!
else
cout<<num<<$ is not
prime$<<endl! return 0!
5
7ai 9erma (:04;;0:)
K
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 17/25
=utput'
7ai 9erma (:04;;0:)
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 18/25
Q. Write a program to implement ABJ algorithm.
pac?age mdJ!
import 6aa.io.BataFnput&tream!
import [email protected]!
pulic class AdJ {
pulic static oid main(&tring[ args) thro-s %ception
{ BataFnput&tream in , ne-
BataFnput&tream(&@stem.in)!
&@stem.out.print($%nter a string '$)!
&tring pass-ord , in.?areadine()!
AessageBigest md , AessageBigest.getFnstance($ABJ$)!
md.update(pass-ord.getN@tes())!
@te @teBata[ , md.digest()!
HHconert the @te to he ormat method
&tringNuer s , ne- &tringNuer()!
or (int i , 0! i < @teBata.length! i11) {
s.append(Fnteger.to&tring((@teBata[i + 0) 1 000* K).sustring())!
5
&@stem.out.println($Bigest(in he ormat)'' $ 1 s.to&tring())!
HHconert the @te to he ormat method :
7ai 9erma (:04;;0:)
8
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 19/25
&tringNuer he&tring , ne- &tringNuer()!
or (int i , 0! i < @teBata.length! i11) {
&tring he , Fnteger.toXe&tring(0 +
@teBata[i)! i (he.length() ,, ) {
he&tring.append(/0/)!
5
he&tring.append(he)!
5
&@stem.out.println($Bigest(in he ormat)'' $ 1 he&tring.to&tring())!
5
5
7ai 9erma (:04;;0:)
L
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 20/25
=utput'
7ai 9erma (:04;;0:)
:0
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 21/25
Q. Write a program to implement 7& algorithm.
#include<stdio.h>
#include<conio.h>
#include<stdli.h>
#include<math.h>
#include<string.h>
long int p*V*n*t*lag*e[00*d[00*temp[00*6*m[00*en[00*i! char msg[00! int
prime(long int)! oid ce()! long int cd(long int)! oid encr@pt()! oid decr@pt()! oid main()
{
clrscr()!
print($n%"M%7 F7&M G7FA%
"PAN%7n$)! scan($d$*+p)!
lag,prime(p)! i(lag,,0)
{ print($nW7="E
F"GPMn$)! getch()!
eit()!
5print($n%"M%7 "=MX%7 G7FA%
"PAN%7n$)! scan($d$*+V)!
lag,prime(V)! i(lag,,0UUp,,V)
{ print($nW7="E
F"GPMn$)! getch()!
eit()!
5print($n%"M%7
A%&&E%n$)! lush(stdin)!
scan($s$*msg)! or(i,0!msg[i
,"P!i11) m[i,msg[i!
n,pIV! t,(p3
)I(V3)!ce()!
print($nG=&&FN% 9P%& = e "B d 7%n$)! or(i,0!i<63
!i11) print($nldtld$*e[i*d[i)!
encr@pt()!
decr@pt()!
getch()!
7ai 9erma (:04;;0:)
:
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 22/25
5 int prime(long int
pr) { int i!
6,sVrt(pr)! or(i,:!i<,6!i11)
{i(pri,,0)return 0!
5 return
! 5 oid
ce() { int
?!
?,0! or(i,:!i<t!i11)
?,?1t!
i(?,,0)
return(?H)!
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 23/25
{i(ti,,0)
continue!lag,prime(i)!
i(lag,,++i,p++i,V)
{ e[?,i!
lag,cd(e[?)!
i(lag>0)
{ d[?,lag!
5 ?11!
i(?,,LL)
5 5 rea?!
5 long int cd(long int )
{ long int ?,! -hile()
{
5
5 oid encr@pt()
{ long int
pt*ct*?e@,e[0*?*len! i,0!
len,strlen(msg)! -hile(i,len)
{pt,m[i!
pt,pt3LK!
7ai 9erma (:04;;0:)
::
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 24/25
?,!
or(6,0!6<?e@!611)
{ ?,?Ipt!
5 ?,?n!
temp[i,?!
ct,?1LK!en[i,ct!
5 i11!
en[i,3!
print($nMX% %"C7RGM%B A%&&E% F&n$)! or(i,0!en[i,3
!i11) print($c$*en[i)!5 oid decr@pt(){ long int pt*ct*?e@,d[0*?!
i,0! -hile(en[i,3)
{ct,temp[i!?,!
or(6,0!6<?e@!611)
{ ?,?Ict!
5 ?,?n!
pt,?1LK!m[i,pt!
5 i11!
m[i,3!
print($nMX% B%C7RGM%B A%&&E% F&n$)! or(i,0!m[i,3
!i11) print($c$*m[i)!
5
7ai 9erma (:04;;0:)
:;
7/21/2019 report on AI
http://slidepdf.com/reader/full/report-on-ai 25/25
=utput'
7ai 9erma (:04;;0:)
:4