diff --git a/C++/Merge_sort.cpp b/C++/Merge_sort.cpp new file mode 100644 index 00000000..3d6eef25 --- /dev/null +++ b/C++/Merge_sort.cpp @@ -0,0 +1,61 @@ +/* +chiragchandnani10 +https://github.com/chiragchandnani10 +*/ + +#include +using namespace std; +void merging(int input[],int start,int end){ + int mid = (start+end)/2; + int i=start, j=mid+1, k=start; + int ans[end+1]; + while(i<=mid&&j<=end){ + if(input[i]=end){ + return; + } + int mid = ((start+end)/2); + merge_sort(input,start,mid); + merge_sort(input,mid+1,end); + merging(input,start,end); + + +} + + + +void mergeSort(int input[], int size){ + // Write your code here + + merge_sort(input,0,size-1); + + + +} + diff --git a/C++/Power_of_2.cpp b/C++/Power_of_2.cpp new file mode 100644 index 00000000..5ed4997a --- /dev/null +++ b/C++/Power_of_2.cpp @@ -0,0 +1,18 @@ +// Author: ADARSH +// Date Modified: 01/10/2022 + +#include +using namespace std; + +bool isPowerOf2(int n) { + return (n && !(n & (n - 1))); +} + +int main(int argc, char const *argv[]) +{ + int n; + cout << "Enter a number: "; + cin >> n; + cout << ((isPowerOf2(n)) ? "It's a power of 2." : "It's not a power of 2."); + return 0; +} diff --git a/C++/factorialprogram.cpp b/C++/factorialprogram.cpp new file mode 100644 index 00000000..992da77a --- /dev/null +++ b/C++/factorialprogram.cpp @@ -0,0 +1,17 @@ +#include +using namespace std; +// github username navdeepk037 https://github.com/navdeepk037 +int fact(int n) +{ + int factorial=1; + for(int i=n;i>=1;i--) + factorial=factorial*i; + return factorial; +} +int main(){ + int n; + cout<<"enter the number "; + cin>>n; + cout<<"the factorial of the number is "< + +void printArray(int *A,int n) +{ + for(int i=0;i A[j+1]) + { + temp = A[j]; + A[j] = A[j+1]; + A[j+1] = temp; + } + } + } +} + +int main() +{ + int A[] = {5,7,3,1,2}; + int n = 5; + printArray(A,n); + BubbleSort(A,n); + printArray(A,n); + +} + diff --git a/C/selection_sort.c b/C/selection_sort.c new file mode 100644 index 00000000..111f56f9 --- /dev/null +++ b/C/selection_sort.c @@ -0,0 +1,56 @@ +/* +Author : Prathamesh Patil +In selection sort, +we get the least from array and place it at first position, then recursively leaving the first element do the same +*/ + + +#include + +//declaration of display function +void display(int array[], int size) +{ + for (int i = 0; i < size; i++) + { + printf("%d ", array[i]); + } +} + +//declaration of funtion :- selection sort +void selection_sort(int array[], int size) +{ + int least, i, j, temp, l; + + for ( i = 0; i < size; i++) //loop for accessing the ith element from array + { + least = array[i]; //taking the i element as the least starting from 0 + printf("Least : %d") + + for ( j = i + 1; j < size; j++) //loop for comparing the array elements with ith element + { + if (least > array[j]) //getting the least element from the array + { + least = array[j]; //storing it in the least variable + l=j; //storing the index of least variable in l + } + } + //swap logic in least and ith element + temp = array[i]; + array[i] = array[l]; + array[l] = temp; + } +} + +int main() +{ + int array[5] = {23,11,1,35,21}; + int size = 5; + + //calling the selection_sort funtion + selection_sort(array, size); + + //calling the display function + display(array, size); + + return 0; +} diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index ce9fc155..a06fe4ce 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -17,6 +17,7 @@ | Khushi Marothi | Khushi Marothi | E-Mail | | Aditya Giri | Aditya Giri | E-Mail | | KryPtoN | Kry9toN | E-Mail | +| Udyansingh | Udyan Singh | E-Mail | | Hardik Pratap Singh | Hardik Pratap Singh | E-Mail | | Suraj Bhandarkar S | Adarsh Addee | E-Mail | | Ashutosh Shukla|Ashutosh Shukla|E-mail | @@ -28,8 +29,27 @@ | Aditya Wadkar | Aditya Wadkar | E-Mail | | Rahul Jangle | Ronny | E-Mail | | Anurag Vats | Anurag Vats | E-Mail | -| Daksh Kesarwani | Daksh kesaarwani | E-Mail | -| Aritroo Chowdhury | Aritroo Chowdhury | E-Mail | +| Daksh Kesarwani | Daksh kesaarwani | E-Mail | +| Aritroo Chowdhury | Aritroo Chowdhury | E-Mail | +| Daksh Kesarwani | Daksh kesaarwani | E-Mail | +| Kartikey Singh | Kartikey Singh | E-Mail | +| Daksh Kesarwani | Daksh kesaarwani | E-Mail | +| Pradeep Khatri | Pradeep Khatri | E-Mail | +| Apurva Dubey | umbridge | E-Mail | +| Daksh Kesarwani | Daksh kesaarwani | E-Mail | +| Chirag Chandnani | Chirag Chandnani | E-Mail | +| Shivam Jaiswal | Shivam Jaiswal | E-mail | +| Ashish Kushwaha | Ashish Kushwaha | E-Mail | +| Dhruv Arora | Dhruv Arora | E-Mail | +| Tharindu Sooriyaarchchi | E-Mail | +| Samriddh Prasad | Samriddh Prasad | E-Mail | +| Edgar Gonzalez | Edgar Gonzalez | E-Mail | + + + + + + diff --git a/Dart/numbers.dart b/Dart/numbers.dart new file mode 100644 index 00000000..c29550b5 --- /dev/null +++ b/Dart/numbers.dart @@ -0,0 +1,7 @@ +//Print 1 to 100 without using numbers +void main() { + int limite = int.parse("100"); + for (int i = 1; i <= limite; i++) { + print(i); + } +} \ No newline at end of file diff --git a/Java/InsertionSort.java b/Java/InsertionSort.java new file mode 100644 index 00000000..a4a8048f --- /dev/null +++ b/Java/InsertionSort.java @@ -0,0 +1,38 @@ +/*Tharindu Sooriyaarachchi - https://github.com/TharinduDilshan */ +public class InsertionSort +{ + void insert(int a[]) + { + int i, j, temp; + int n = a.length; + for (i = 1; i < n; i++) { + temp = a[i]; + j = i - 1; + + while(j>=0 && temp <= a[j]) + { + a[j+1] = a[j]; + j = j-1; + } + a[j+1] = temp; + } + } + void printArr(int a[]) + { + int i; + int n = a.length; + for (i = 0; i < n; i++) + System.out.print(a[i] + " "); + } + + public static void main(String[] args) { + int a[] = { 92, 50, 5, 20, 11, 22 }; + InsertionSort i1 = new InsertionSort(); + System.out.println("\nBefore sorting array elements are - "); + i1.printArr(a); + i1.insert(a); + System.out.println("\n\nAfter sorting array elements are - "); + i1.printArr(a); + System.out.println(); + } +} \ No newline at end of file diff --git a/Java/QuickSort.java b/Java/QuickSort.java new file mode 100644 index 00000000..78f3d20d --- /dev/null +++ b/Java/QuickSort.java @@ -0,0 +1,51 @@ +//Github Username: Udyansingh + +import java.util.Arrays; +import java.util.Scanner; + +public class QuickSort { + + public static int partition(int[] arr, int si, int ei) { + int pid, piv = arr[si], count = 0, i = si; + for (i = si + 1; i <= ei; i++) { + if (arr[i] <= piv) { + count++; + } + } + pid = count + si; + arr[si] = (arr[pid] + arr[si]) - (arr[pid] = arr[si]); + while (si < pid && ei > pid) { + if (arr[si] < piv) { + si++; + } else if (arr[ei] > piv) { + ei--; + } else { + arr[si] = (arr[ei] + arr[si]) - (arr[ei--] = arr[si++]); + } + } + return pid; + } + + public static void quickSort(int[] arr, int si, int ei) { + if (si < ei) { + int p = partition(arr, si, ei); + quickSort(arr, si, p - 1); + quickSort(arr, p + 1, ei); + } + } + + public static void main(String[] args) { + Scanner sc = new Scanner(System.in).useDelimiter(","); + System.out.println("Hint: Enter Array -> 1,2,3,4,5,6 "); + System.out.print("Enter Array -> "); + String input = sc.nextLine(); + String[] split = input.split(","); + int[] arr = new int[split.length]; + for (int i = 0; i < split.length; i++) { + arr[i] = Integer.parseInt(split[i]); + } + quickSort(arr, 0, arr.length - 1); + System.out.println("Sorted Array -> " + Arrays.toString(arr)); + sc.close(); + } +} diff --git a/Python/Steganography.py b/Python/Steganography.py new file mode 100644 index 00000000..af6f8ee1 --- /dev/null +++ b/Python/Steganography.py @@ -0,0 +1,133 @@ +# Shivamsinghal679 + +import cv2 +import numpy as np +import types +from google.colab.patches import cv2_imshow + +# converting types to binary +def msg_to_bin(msg): + if type(msg) == str: + return ''.join([format(ord(i), "08b") for i in msg]) + elif type(msg) == bytes or type(msg) == np.ndarray: + return [format(i, "08b") for i in msg] + elif type(msg) == int or type(msg) == np.uint8: + return format(msg, "08b") + else: + raise TypeError("Input type not supported") + +# defining function to hide the secret message into the image +def hide_data(img, secret_msg): + # calculating the maximum bytes for encoding + nBytes = img.shape[0] * img.shape[1] * 3 // 8 + print("Maximum Bytes for encoding:", nBytes) + # checking whether the number of bytes for encoding is less + # than the maximum bytes in the image + if len(secret_msg) > nBytes: + raise ValueError("Error encountered insufficient bytes, need bigger image or less data!!") + secret_msg += '#####' # we can utilize any string as the delimiter + dataIndex = 0 + # converting the input data to binary format using the msg_to_bin() function + bin_secret_msg = msg_to_bin(secret_msg) + + # finding the length of data that requires to be hidden + dataLen = len(bin_secret_msg) + for values in img: + for pixels in values: + # converting RGB values to binary format + r, g, b = msg_to_bin(pixels) + # modifying the LSB only if there is data remaining to store + if dataIndex < dataLen: + # hiding the data into LSB of Red pixel + pixels[0] = int(r[:-1] + bin_secret_msg[dataIndex], 2) + dataIndex += 1 + if dataIndex < dataLen: + # hiding the data into LSB of Green pixel + pixels[1] = int(g[:-1] + bin_secret_msg[dataIndex], 2) + dataIndex += 1 + if dataIndex < dataLen: + # hiding the data into LSB of Blue pixel + pixels[2] = int(b[:-1] + bin_secret_msg[dataIndex], 2) + dataIndex += 1 + # if data is encoded, break out the loop + if dataIndex >= dataLen: + break + + return img + +def show_data(img): + bin_data = "" + for values in img: + for pixels in values: + # converting the Red, Green, Blue values into binary format + r, g, b = msg_to_bin(pixels) + # data extraction from the LSB of Red pixel + bin_data += r[-1] + # data extraction from the LSB of Green pixel + bin_data += g[-1] + # data extraction from the LSB of Blue pixel + bin_data += b[-1] + # split by 8-Bits + allBytes = [bin_data[i: i + 8] for i in range(0, len(bin_data), 8)] + # converting from bits to characters + decodedData = "" + for bytes in allBytes: + decodedData += chr(int(bytes, 2)) + # checking if we have reached the delimiter which is "#####" + if decodedData[-5:] == "#####": + break + # print(decodedData) + # removing the delimiter to display the actual hidden message + return decodedData[:-5] + +# defining function to encode data into Image +def encodeText(): + img_name = input("Enter image name (with extension): ") + # reading the input image using OpenCV-Python + img = cv2.imread(img_name) + + # printing the details of the image + print("The shape of the image is: ", img.shape) # checking the image shape to calculate the number of bytes in it + print("The original image is as shown below: ") + # resizing the image as per the need + resizedImg = cv2.resize(img, (500, 500)) + # displaying the image + cv2_imshow(resizedImg) + + data = input("Enter data to be encoded: ") + if (len(data) == 0): + raise ValueError('Data is Empty') + + file_name = input("Enter the name of the new encoded image (with extension): ") + # calling the hide_data() function to hide the secret message into the selected image + encodedImage = hide_data(img, data) + cv2.imwrite(file_name, encodedImage) + +# defining the function to decode the data in the image +def decodeText(): + # reading the image containing the hidden image + img_name = input("Enter the name of the Steganographic image that has to be decoded (with extension): ") + img = cv2.imread(img_name) # reading the image using the imread() function + + print("The Steganographic image is as follow: ") + resizedImg = cv2.resize(img, (500, 500)) # resizing the actual image as per the needs + cv2_imshow(resizedImg) # displaying the Steganographic image + + text = show_data(img) + return text + +# image steganography +def steganography(): + n = int(input("Image Steganography \n1. Encode the data \n2. Decode the data \n Select the option: ")) + if (n == 1): + print("\nEncoding...") + encodeText() + + elif (n == 2): + print("\nDecoding...") + print("Decoded message is " + decodeText()) + + else: + raise Exception("Inserted value is incorrect!") + +steganography() diff --git a/Python/checkpass.py b/Python/checkpass.py new file mode 100644 index 00000000..6db451fb --- /dev/null +++ b/Python/checkpass.py @@ -0,0 +1,39 @@ +# AkashShaw27 + + +import requests +import hashlib +import sys +def request_api_data(query_char): + url="https://api.pwnedpasswords.com/range/" + query_char + res=requests.get(url) + if res.status_code !=200: + raise RuntimeError(f'Error fetching: {res.status_code}, check the api and try again') + return res +def get_password_leaks_count(hashes, hash_to_check): + hashes=(line.split(':') for line in hashes.text.splitlines()) + for h, count in hashes: + if h==hash_to_check: + return count + return 0 +def pwned_api_check(password): + sha1password=hashlib.sha1(password.encode('utf-8')).hexdigest().upper() + first5_char, tail=sha1password[:5],sha1password[5:] + response=request_api_data(first5_char) + return get_password_leaks_count(response,tail) + #Check password if it exists in API response +def main(args): + for password in args: + count=pwned_api_check(password) + if count: + print(f'{password} was found {count} times... You should probably change your password') + else: + print(f'{password} was NOT found. Carry on!') + return 'done!' +if __name__=='__main__': + main(sys.argv[1:]) + + + + + diff --git a/Python/snakegame.py b/Python/snakegame.py new file mode 100644 index 00000000..596b4c7a --- /dev/null +++ b/Python/snakegame.py @@ -0,0 +1,48 @@ +from random import randrange +from freegames import square,vector + +food=vector(0,0) +snake=[vector(10,0)] +aim=vector(0,-10) + +def change(x,y): + aim.x=x + aim.y=y + +def inside(head): + return -200 < head.x < 190 and -200 < head.y < 190 + +def move(): + head=snake[-1].copy() + head.move(aim) + if not inside(head) or head in snake: + square(head.x,head.y,9,"red") + update() + return + snake.append() + + if head==food: + print("snake",len(snake)) + food.x=randrange(-15,15)*10 + food.y=randrange(-15,15)*10 + else: + snake.pop(0) + clear() + + for body in snake: + square(body.x,body.y,9,"green") + + square(food.x,food,y,9,"red") + update() + ontimer(move,100) + + hideturtle() + tracer(false) + listen() + onkey(lambda:changes(10,0),"Right") + onkey(lambda:changes(-10,0),"Left") + onkey(lambda:changes(0,10),"Up") + onkey(lambda:changes(0,-10),"Down") + + move() + done() diff --git a/Python/tic_tac_toe_game.py b/Python/tic_tac_toe_game.py new file mode 100644 index 00000000..938345f4 --- /dev/null +++ b/Python/tic_tac_toe_game.py @@ -0,0 +1,104 @@ +""" +Program : A tic tac toe game written in Python which can be played between 2 players +Github Username : @AshishKingdom +""" + +class TicTacToe: + """ + init some variables required for this class + """ + def __init__ (self): + self.board = [['1','2','3'],['4','5','6'],['7','8','9']] + self.player1 = "X" + self.player2 = "O" + self.game_over = False + return + + """ + draws the current board data in a good format + """ + def draw_board(self): + p = 0 + print("\n\n") + for i in self.board: + print(f" {i[0]} | {i[1]} | {i[2]} ") + if p<2: + print("-------------") + p = p + 1 + print() + return + + + def set_value(self, position, t): + for b in self.board: + for i in range(0,3): + if b[i]==position: + b[i] = t + return True + + # if player enters wrong position + print("Invalid Input! Please enter value between 1-9 only!") + print("Enter your move again (1-9) : ") + return False + + """ + plays the current game until the game gets tie or a player wins + """ + def play(self): + current_chance = 1 # 1-> player1 chance, -1 -> player 2 chance + while self.game_status()==0: + self.draw_board() + if current_chance==1: + cp = "X" + print("Player 1, Enter your move (1-9) : ") + else: + cp = "O" + print("Player 2, Enter your move (1-9) : ") + while not self.set_value(input(), cp): + pass + current_chance = current_chance * -1 # switch between 1 and -1 + + self.draw_board() + s = self.game_status() + if s==1: + print("Player 1 Wins!!!") + elif s==2: + print("Player 2 Winns!!!") + else: + print("It's a TIE!!!") + + + """ + returns 1 if player1 has won, 2 if player2 has won, 3 if the game has tie + 0 if the game is still in progress + """ + def game_status(self): + + b = self.board + for i in range(0,3): #row case + if b[i][0]=='X' and b[i][1]=='X' and b[i][2]=='X': + return 1 + if b[i][0]=='O' and b[i][1]=='O' and b[i][2]=='O': + return 2 + + for i in range(0,3): #column case + if b[0][i]=='X' and b[1][i]=='X' and b[2][i]=='X': + return 1 + if b[0][i]=='O' and b[1][i]=='O' and b[2][i]=='O': + return 2 + #diagonal case + if (b[0][0]=='X' and b[1][1]=='X' and b[2][2]=='X') or (b[0][2]=='X' and b[1][1]=='X' and b[2][0]=='X'): + return 1 + if (b[0][0]=='O' and b[1][1]=='O' and b[2][2]=='O') or (b[0][2]=='O' and b[1][1]=='O' and b[2][0]=='O'): + return 2 + #checking if their is a tie + for i in range(0,3): + for d in "123456789": + if d in b[i]: + return 0 #one more chance is left + return 3 # its a tie! + + +if __name__ == "__main__": + game = TicTacToe() + game.play() \ No newline at end of file diff --git a/README.md b/README.md index 91517da3..3fa1e539 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# ✨Hacktoberfest 2022✨ +# ✨#Hacktoberfest 2022✨ A Simple😉 beginner friendly😊 Repo for all programmers and coders. All contributors are requested to star🌟this repo and and folllllow me. Contribute to start your journey with hacktoberfest and python. Happy Hacking💻!!! (*Required) @@ -6,37 +6,52 @@ Contribute to start your journey with hacktoberfest and python. Happy Hacking # 🌟Languages - 💻 C - 💻 C++ -- 💻 HTML - 💻 PHP - 💻 Python - 💻 Java - 💻 Javascript +# 🛡Rules to Contribute +- ⚓Star this repo to get latest updates. +- ⚓Give your file a proper extension according to language. Ex. .py, .java, .js. html etc. +- ⚓Name your file related to your topic. +- ⚓Put your files in correct folder like .py in Python, .js in Javascript etc. +- ⚓Make sure you have entered your github - username, aim and date in your file as a comment. +- ⚓Make sure you have entered your name in CONTRIBUTORS.md file as mentioned (It's your responsibility) (optional). +- ⚓You can follow ME😁. + +# ❄Format of 5th line in rules +
// Github username: Your Username
+// Aim: Your Repo aim according to your program
+// Date: Date of Coding
+
+// start coding
+
+
+ +### ⚡If your program have class try to use your class with its objects + +### ⚡If you are creating any PR then Add your name in CONTRIBUTORS.md file + +## 🛡Follow rules strictly for successful merged PR!!! + # ❄Prgrams +- ⚡Create any pattern +- ⚡Make any algorithm (exclude calculator or related to it) - ⚡Print 1 to 100 without using numbers - ⚡Make calculator without using operators in program -- ⚡Create any pattern -- ⚡Make any algorithm -- ⚡Add webpage parts. - ⚡Calculate fibonacci series with classes - ⚡Calculate factorial with classes - ⚡Print IP Address and Hostname -- ⚡Any Game -## Don't forget to read the contributing rules mentioned below to be successfully merged your PR and get rewards!!! + +## Don't forget to read the contributing rules above to be successfully merged your PR and get rewards!!! 🏹 Visit Hacktoberfest to get more information about Hacktoberfest 2022!!! ✈ Visit Hacktoberfest-swag to know more about your swags and rewards!!! -# 🛡Rules to Contribute -- ⚓Star this repo to get latest updates. -- ⚓Give your file a proper extension according to language. Ex. .py, .java, .js. html etc. -- ⚓Name your file related to your topic. -- ⚓Put your files in correct folder like .py in Python, .js in Javascript etc. -- ⚓Make sure you have entered your github - username in your file as a comment. -- ⚓Make sure you have entered your name in CONTRIBUTORS.md file as mentioned (It's your responsibility). -- ⚓You can follow ME😁. +# 🛡 Strictly follow rules to contribute for successful merged PR!!! # Note All contributors who have followed the rules to contribute get successfully merged PR. Don't forget to follow!!!