Skip to content

Commit 548ce27

Browse files
2 parents 2678e24 + 66a701c commit 548ce27

12 files changed

+195
-12
lines changed

Challenge questions/Readme.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@ Wish to give a challenge? sure just make an edit, and throw the pull request ;)
1515

1616
## Challenge:
1717
1. Write a Code that accepts String in a format like "My name is someone", then it has to be formatted into "MyNameIsSomeone" and then back to original
18-
2. ***Challenge Awaits***
19-
3. ***Challenge Awaits***
20-
4. ***Challenge Awaits***
21-
5. ***Challenge Awaits***
18+
2. Write a Code that accepts the inversemod of num to inversemodnum -> num inverse% inversemodnum = ?
19+
3. Write a Code that scrambles the words by following the rules below:
20+
a)Words less than or equal to 3 characters need not be scrambled .
21+
b)Don't scramble first and last char, so Scrambling can become Srbmnacilg or Srbmnailcg or Snmbracilg , i.e. letters except first and last can be scrambled in any order .
22+
c)Punctuation at the end of the word to be maintained as is i.e. "Surprising," could become "Spsirnirug," but not "Spsirn,irug" .
23+
d)Following punctuation marks are to be supported - Comma Question mark, Full stop, Semicolon, Exclamation .
24+
e)Do this for a file and maintain sequences of lines .
25+
4. Reading from a CSV file and printing all colums as rows.
26+
5. Given Strings of code equations like, "45 >= 67 56==70 30 <= 78" and output should be binary "0 0 1" { input is seprated with space and output should be on new line}
2227
6. ***Challenge Awaits***
2328
7. ***Challenge Awaits***
2429
---------------------------------------------------------------------------------------------------------------------------------------
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This wlil slreuy get sbraclemd This is aa ionsfys pjoecrt It scaembrls the leertts in eervy word of eervy snctcenee in the gevin file
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This will surely get scrambled This is a infosys project It scrambles the letters in every word of every scentence in the given file
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import random
2+
import os
3+
def shuf(string):
4+
ltemp=string[1:len(string)-1] # taking only the mid part { change it into string[0:len(string)] for a full words shuffle
5+
ltemp=list(ltemp) # convert the word into alphabet list eg: "hey" -> ["h","e","y"]
6+
random.shuffle(ltemp) # shuffles the alphabet
7+
ltemp="".join(ltemp) # join the alphabet back to a word
8+
ltemp=string[0]+ltemp+string[len(string)-1] # add the first and the end alphabet to the word
9+
return ltemp # returns the shuffled word
10+
11+
def filewrite(stext):
12+
f=open("output.txt","w")
13+
f.write(stext)
14+
15+
16+
def wordscramble():
17+
#f=open("word.txt","r")
18+
fn=input("Enter file name:")
19+
f=open(fn,"r")
20+
text=f.read()
21+
print("The text before scrambling:", text)
22+
text=text.split() # this splits words from string
23+
stext=[] #scramble list { empty }
24+
for i in range(len(text)):
25+
stext.append(shuf(text[i])) # shuffles the word mid part only , starting and ending alphabets are not touched
26+
stext=" ".join(stext)
27+
print("The text after scrambling:") # joins the words into a string again
28+
print(stext)
29+
filewrite(stext)
30+
31+
32+
33+
wordscramble() # scramble's the file text
34+
35+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
extract=[]
2+
def mod(a,modnum):
3+
global extract
4+
left=0
5+
addnum=0
6+
for i in range(0,modnum):
7+
if((modnum-a*i)>0):
8+
left=i
9+
addnum=modnum-a*i
10+
continue
11+
break
12+
if(addnum != 1):
13+
extract.append(mod(addnum,a))
14+
return left,addnum
15+
16+
print(mod(11,26))
17+
print(extract)
18+
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def egcd(a, b):
2+
if a == 0:
3+
return (b, 0, 1)
4+
else:
5+
g, y, x = egcd(b % a, a)
6+
return (g, x - (b // a) * y, y)
7+
8+
def modinv(a, m):
9+
g, x, y = egcd(a, m)
10+
if g != 1:
11+
raise Exception('modular inverse does not exist')
12+
else:
13+
return x % m
14+
15+
print(egcd(10,12))
16+
print(modinv(11,26))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import csv
2+
3+
with open('data.csv') as csvfile:
4+
readCSV =csv.reader(csvfile,delimiter=',')
5+
ager=[]
6+
genderr=[]
7+
racer=[]
8+
for row in readCSV:
9+
age= row[0]
10+
gender=row[1]
11+
race=row[2]
12+
ager.append(age)
13+
genderr.append(gender)
14+
racer.append(race)
15+
print(ager,genderr,racer)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
23,male,white
2+
34,male,brown
3+
56,female,black
4+
34,female,brown
5+
27,male,black
6+
73,male,white
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def imod(inv, modnum):
2+
goal = 1
3+
while (goal % inv > 0):
4+
goal += modnum
5+
print(goal)
6+
return goal // inv
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
def bin(instrlist):
2+
#instr=input("Enter your String ")
3+
#instrlist=instr.split()
4+
# print(instrlist)
5+
a=eval(instrlist[0])
6+
b=eval(instrlist[-1])
7+
if '==' in instrlist:
8+
if(a==b):
9+
print(1)
10+
else:
11+
print(0)
12+
if '!=' in instrlist:
13+
if(a!=b):
14+
print(1)
15+
else:
16+
print(0)
17+
if '>=' in instrlist:
18+
if(a>=b):
19+
print(1)
20+
else:
21+
print(0)
22+
if '<=' in instrlist:
23+
if(a==b):
24+
print(1)
25+
else:
26+
print(0)
27+
28+
listinstr=input("enter your input")
29+
listinstr=listinstr.split()
30+
# print(listinstr)
31+
for i in range(0,len(listinstr),3):
32+
# print(i,999)
33+
# print(listinstr[i:i+3])
34+
bin(listinstr[i:i+3])

Ciphers/Caesar_cipher.py

+30-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# making of Caesar Cipher
2+
import sys
23
seriesEnlv1=dict()
34
seriesDelv1=dict()
45
seriesEnlv2=dict()
@@ -13,10 +14,16 @@ def mapping():
1314
seriesEnlv1[alphalv1[i]]=i
1415
seriesDelv1[i]=alphalv1[i]
1516
alphalv2='ZYXWVUTSRQPONMLKJIHGFEDCBA'
16-
for i in range(-25,0):
17+
for i in range(-26,0):
1718
seriesEnlv2[alphalv2[i]]=i
1819
seriesDelv2[i]=alphalv2[i]
19-
20+
21+
def check(message):
22+
for i in message:
23+
if((i==" " or i.isalpha())==False):
24+
print("\n Message can't be send, remove any numbers or special symbols to continue ")
25+
raise Exception(" message fault ")
26+
2027

2128
def message(code):
2229
mess=[]
@@ -59,6 +66,12 @@ def remodify(string):
5966

6067
def textconv(text,key):
6168
mapping()
69+
key=key%26
70+
try:
71+
check(text)
72+
except:
73+
print(" Message format is incorrect ")
74+
sys.exit()
6275
text=modify(text)
6376
code=[]
6477
global seriesEnlv1
@@ -69,9 +82,11 @@ def textconv(text,key):
6982
else:
7083
code.append((seriesEnlv1[i]+key)%26)
7184
return (message(code))
85+
7286

7387
def textrevert(encoded,key):
7488
code=[]
89+
key=key%26
7590
global seriesEnlv1
7691
for i in encoded:
7792
if (i.islower()):
@@ -85,12 +100,19 @@ def textrevert(encoded,key):
85100
code.append(x)
86101
return remodify(message(code))
87102

88-
simpleText=input("Enter the simple text : ")
89-
key=int(input(" Enter the key for the Text :"))
90-
encoded=textconv(simpleText,key)
91-
print(encoded)
92-
decoded=textrevert(encoded,key)
93-
print(decoded)
103+
def main():
104+
simpleText=input("Enter the simple text : ")
105+
try:
106+
key=int(input(" Enter the key for the Text :"))
107+
except:
108+
print(" Enter only numeric key ")
109+
sys.exit()
110+
encoded=textconv(simpleText,key)
111+
print(encoded)
112+
decoded=textrevert(encoded,key)
113+
print(decoded)
114+
115+
main()
94116

95117

96118

Ciphers/railfence.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#rail fence
2+
3+
string=input("Enter the string :")
4+
part1,part2='',''
5+
i=1
6+
if(len(string)%2!=0):
7+
string+=" "
8+
while(i<len(string)):
9+
part1+=string[i-1]
10+
part2+=string[i]
11+
i=i+2
12+
print(part1+part2)
13+
14+
newString=part1+part2
15+
newpart1=newString[0:len(newString)//2+1]
16+
newpart2=newString[len(newString)//2:]
17+
18+
i=1
19+
backString=''
20+
while(i<max(len(newpart1),len(newpart2))):
21+
backString=backString+newpart1[i-1]+newpart2[i-1]
22+
i+=1
23+
print(backString)

0 commit comments

Comments
 (0)