Pratik Ghelani

Pratik Ghelani

Breaking

Thursday, August 27, 2020

12:17 PM

Check the string is palindrome or not in swift

 var str = "Pratik"

var str1 = String(str.reversed())

if (str == str1)

{

print("String is Palidrome")

}

else

{

print("String is Not Palidrome")

}

var str = "aba"

var str1 = String(str.reversed())

if (str == str1)

{

print("String is Palidrome")

}

else

{

print("String is Not Palidrome")

}

Sunday, May 10, 2020

6:27 AM

Implementation of polyalphabetic cipher.

Input:-


public class polyalphabetic {
public static void main(String[] args) {
String s="playcsgo";
String k="playeveryday";
//String s="abc";
//String k="def";
String ans="";
char km[][]=new char[26][26];
for(int i=0;i<26;i++)
{
for(int j=0;j<26;j++)
{
km[i][j]=(char)((j+'a'+i)>'z'?(j+'a'+i-26):(j+'a'+i));
System.out.print(km[i][j]+" ");
}
System.out.println("");
}
for(int z=0;z<s.length();z++)
{
//ans+=km[('a'+k.charAt((z%k.length()))+1)%26][('a'+s.charAt(z)+1)%26];
ans+=km[k.charAt(z%k.length())-'a'][(s.charAt(z)-'a')];
}
System.out.println(ans);
String dec="";
int i=0;
while(i<ans.length())
{
for(int j=0;j<26;j++)
{
if(km[k.charAt(i%k.length())-'a'][j]==ans.charAt(i))
{
dec+=(char)(j+'a');
//System.out.println(j+'a');
}
}
i++;
}
System.out.println(dec);
//System.out.println(km[1][1]);*/
}
}

Output:-


Output:-

6:24 AM

Implementation of Caesar ciphar in java

Input:-

import java.util.Scanner;
public class main {
public static void main(String[] args) {
int i,key = 0;
char pt[] = new char[50];
char ct[] = new char[50];
Scanner s = new Scanner(System.in);
System.out.print("Enter the Plain text:");
String str = s.next();
pt = str.toCharArray();
System.out.print("Enter the key:");
key = s.nextInt();
System.out.println("---Encryption---");
System.out.print("Ciphertext:");
for(i = 0 ; i<str.length() ; i++)
{
if(pt[i]>=65 && pt[i]<=90){
ct[i] = (char)(pt[i] + key);
if(ct[i]<65){
ct[i] = (char)(ct[i] + 26);
}
if(ct[i]>90){
ct[i] = (char)(ct[i] - 26);
}
}
else
{
ct[i] = (char)(pt[i] + key);
if(ct[i]<97){
ct[i] = (char)(ct[i] + 26);
}
if(ct[i]>122){
ct[i] = (char)(ct[i] - 26);
}
}
System.out.print(ct[i]);
}
System.out.println();
System.out.println("---Decryption---");
System.out.print("Original Plaintext:");
for(i = 0 ; i<str.length() ; i++)

{
if(ct[i]>=65 && ct[i]<=90){
pt[i] = (char)(ct[i] - key);
if(pt[i]<65){
pt[i] = (char)(pt[i] + 26);
}
if(pt[i]>90){
pt[i] = (char)(pt[i] - 26);
}
}
else
{
pt[i] = (char)(ct[i] - key);
if(pt[i]<97){
pt[i] = (char)(pt[i] + 26);
}
if(pt[i]>122){
pt[i] = (char)(pt[i] - 26);
}
}
System.out.print(pt[i]);
}
System.out.println();
}
}


Output:-



6:17 AM

. Create a list of temperatures in degrees Celsius with the values 25.2,16.8, 31.4, 23.9, 28, 22.5, and 19.6, and assign it to a variable called temps. Using one of the list methods, sort temps in ascending order. Write for loop to convert all the values from temps_in_celsius into Fahrenheit, and store the converted values in a new list temps_in_fahrenheit.

Input:-

n = int(input("Enter the temperature list:"))
Temp = [25.2,16.8, 31.4, 23.9, 28, 22.5,19.6]
b = []


for i in range (0,n):
   
    Temp.append(b)

for i in range (0,n):
    temp1 = (Temp[i]*9/5)+32
    b.append(temp1)

for i in range (0,n):

    print(str(Temp[i]) + " celsius to fahrenheit : "+ str(b[i]))

Output:-


6:15 AM

Create a class “employee” with attributes like id, name, designation, emailid, birthdate, city. a.getData() to take employee information. b.setData() to display employee information. Inherit class “Account” with attributes like acc_id, acc_type, amount and methods to generate account report of peticular employee in proper format. Implement regular expression to validate emailid and birthdate.

Input:-

import re
class employee(object):
    employee_id=0
    employee_name=""
    designation =""
    Email_id=""
    DOB =""
    City =""
    emailmatch = "^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$"
    dateofbirthmatch = "^[0-3]?[0-9]/[0-3]?[0-9]/(?:[0-9]{2})?[0-9]{2}$"

    def set(self,employee_id,employee_name,designation,Email_id,DOB,City):
        self.employee_id=employee_id
        self.employee_name=employee_name
        self.designation=designation
        self.Email_id=Email_id
        self.DOB=DOB
        self.City=City
    def get(self):
        print()
        print("Employee details:-")
        print("Id:-",self.employee_id)
        print("Name:-",self.employee_name)
        print("Designation:-",self.designation)
        if(re.search(self.emailmatch,self.Email_id)):
            print(self.Email_id,"is Valid")
        else:
            print(self.Email_id,"is not Valid")
        if(re.search(self.dateofbirthmatch,self.DOB)):
            print(self.DOB,"is Valid")
        else:
            print(self.DOB,"is not Valid")
        print("City",self.City)

class Account(employee):
    acc_id=0
    acc_type=""
    amount=0

    def set(self,acc_id,acc_type,amount):
        self.acc_id=acc_id
        self.acc_type=acc_type
        self.amount=amount
    def get(self):
        print()
        print("Account details:-")
        print("Account id is:",self.acc_id)
        print("Account type is:",self.acc_type)
        print("amount is:",self.amount)

m = employee()
m.set(1,"Parth","Developer","parthshah01@gmail.com","27/06/1993","Surat")
m.get()
m.set(1,"Parth","Developer","parthshah0ail.com","27/061993","Surat")
m.get()

h = Account()
h.set(2,"Saving Account",25000)

h.get()

Output:-