Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
AdarshAddee committed Oct 3, 2022
2 parents ff747f8 + b9db83a commit 335f299
Show file tree
Hide file tree
Showing 11 changed files with 534 additions and 15 deletions.
18 changes: 18 additions & 0 deletions C++/Power_of_2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Author: ADARSH
// Date Modified: 01/10/2022

#include <bits/stdc++.h>
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;
}
56 changes: 56 additions & 0 deletions C/selection_sort.c
Original file line number Diff line number Diff line change
@@ -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<stdio.h>

//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;
}
10 changes: 10 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
| Khushi Marothi | <a href="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/khushimarothi">Khushi Marothi</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Aditya Giri | <a href="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/aditya-464">Aditya Giri</a> | <a href="mailto:[email protected]">E-Mail</a> |
| KryPtoN | <a href="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/Kry9toN">Kry9toN</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Udyansingh | <a href="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/Udyansingh">Udyan Singh</a> | <a href="[email protected]">E-Mail</a> |
| Hardik Pratap Singh | <a href="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/hardik-pratap-singh">Hardik Pratap Singh</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Suraj Bhandarkar S | <a href="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/Suraj-Bhandarkar-S">Adarsh Addee</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Ashutosh Shukla|<a href = "https://github.com/AshutoshBuilds">Ashutosh Shukla</a>|<a href ="[email protected]">E-mail</a> |
Expand All @@ -28,8 +29,17 @@
| Aditya Wadkar | <a href="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/AdityaWadkar">Aditya Wadkar</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Rahul Jangle | <a href="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/Rronny01/">Ronny</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Anurag Vats | <a href="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/AnuragVats007">Anurag Vats</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Apurva Dubey | <a href="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/umbridge">umbridge</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Daksh Kesarwani | <a href="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/InnocentDaksh63">Daksh kesaarwani</a> | <a href="[email protected]">E-Mail</a> |
| Chirag Chandnani | <a href="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/chiragchandnani10">Chirag Chandnani</a> | <a href="[email protected]">E-Mail</a> |
| Shivam Jaiswal | <a href="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/Shivaminc">Shivam Jaiswal</a> | <a href="[email protected]">E-mail</a> |
| Ashish Kushwaha | <a href="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/AshishKingdom">Ashish Kushwaha</a> | <a href="[email protected]">E-Mail</a> |
| Dhruv Arora | <a href="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/lord-benjamin">Dhruv Arora</a> | <a href="mailto:[email protected]">E-Mail</a> |
| Tharindu Sooriyaarchchi | <a href="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/TharinduDilshan>Tharindu Sooriyaarchchi</a> | <a href="[email protected]">E-Mail</a> |
| Samriddh Prasad | <a href="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/Samriddh2703">Samriddh Prasad</a> | <a href="[email protected]">E-Mail</a> |
| Edgar Gonzalez | <a href="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/Edgarzerocool">Edgar Gonzalez</a> | <a href="[email protected]">E-Mail</a> |





Expand Down
7 changes: 7 additions & 0 deletions Dart/numbers.dart
Original file line number Diff line number Diff line change
@@ -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);
}
}
38 changes: 38 additions & 0 deletions Java/InsertionSort.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
51 changes: 51 additions & 0 deletions Java/QuickSort.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
133 changes: 133 additions & 0 deletions Python/Steganography.py
Original file line number Diff line number Diff line change
@@ -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()
39 changes: 39 additions & 0 deletions Python/checkpass.py
Original file line number Diff line number Diff line change
@@ -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:])





Loading

0 comments on commit 335f299

Please sign in to comment.