Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update passwordGenerator.py #763

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 43 additions & 20 deletions Arrays/01_static_and_dynamicArray.c
Original file line number Diff line number Diff line change
@@ -1,25 +1,48 @@
#include <stdio.h>
#include <stdlib.h>

// Define a constant for array size
#define ARRAY_SIZE 5

int main()
{
int A[5] = { 1,2,3,4,5 }; // this is allocated inside stack memory
int* p; // pointer of array
int i;
p = (int*)malloc(5 * sizeof(int)); // dynamically createing array inside heap
p[0] = 1; // initializing all the terms in array
p[1] = 2;
p[2] = 3;
p[3] = 4;
p[4] = 5;

for (i = 0; i < 5; i++) // iteration for normal array
{
printf("%d ", A[i]);
}
printf("\n");
for (i = 0; i < 5; i++) // iteration for the dynamic array
{
printf("%d ",p[i]);
}
return 0;
// Static array allocated on the stack
int A[ARRAY_SIZE] = {1, 2, 3, 4, 5};
int* p; // Pointer for dynamically allocated array
int i;

// Dynamically create an array on the heap
p = (int*)malloc(ARRAY_SIZE * sizeof(int));
if (p == NULL) // Check if malloc was successful
{
printf("Memory allocation failed!\n");
return 1; // Exit with error code
}

// Initialize the dynamically allocated array
for (i = 0; i < ARRAY_SIZE; i++)
{
p[i] = i + 1; // Assign values (same as static array)
}

// Iterate and print the static array
printf("Static array elements:\n");
for (i = 0; i < ARRAY_SIZE; i++)
{
printf("%d ", A[i]);
}
printf("\n");

// Iterate and print the dynamic array
printf("Dynamic array elements:\n");
for (i = 0; i < ARRAY_SIZE; i++)
{
printf("%d ", p[i]);
}
printf("\n");

// Free dynamically allocated memory
free(p);

return 0;
}
110 changes: 58 additions & 52 deletions Java/Linked List/LinkedList.java
Original file line number Diff line number Diff line change
@@ -1,76 +1,82 @@
//Author: Vaibhav Pandey
//Date Created: 06/03/2022
//Title: Implementing Linked List data structure in Java from scratch
// Author: Vaibhav Pandey
// Date Created: 06/03/2022
// Title: Implementing Linked List data structure in Java from scratch

// Start of LinkedList class
public class LinkedList {

//Start of main LinkedList class
public class LinkedList{

//Node class for storing current node's value and the address to the next node
static class Node{
Node next;
// Node class representing each element in the list
static class Node {
int value;
Node next;

//Constructor that initializes node's value
public Node(int value){
// Constructor to initialize the node's value
public Node(int value) {
this.value = value;
}
}

//Initializing the first node to null
Node first = null;
// Head of the linked list
private Node head = null;

//Function for adding elements at the front of the list
public void addAtFront(Node node){
//Assign the next node's address to first and store the current node's address in first
node.next = first;
first = node;
// Add a node at the front of the list
public void addAtFront(int value) {
Node node = new Node(value);
node.next = head;
head = node;
}

//Function for adding elements at the end of the list
public void addAtEnd(Node node){
//If the list is already empty, just assign the first address to the current node
if(first == null){
first = node;
}
//If the list is not empty, traverse the list from the first element to the last element and add the current node at last
else{
Node ptr = first;
while(ptr.next != null){
ptr = ptr.next;
// Add a node at the end of the list
public void addAtEnd(int value) {
Node node = new Node(value);
if (head == null) { // If the list is empty
head = node;
} else {
Node current = head;
while (current.next != null) {
current = current.next;
}
ptr.next = node;
current.next = node;
}
}

//Function for removing the first element of the list
public void removeFront(){
//To remove the first element, just set the next element to first
first = first.next;
// Remove the first node from the list
public void removeFront() {
if (head != null) { // Check if the list is not empty
head = head.next;
} else {
System.out.println("List is empty. Nothing to remove.");
}
}

// Print the linked list
public void print() {
if (head == null) {
System.out.println("List is empty.");
return;
}

//Function to print the list
public void print(){
//For printing just traverse the list from first to last
Node ptr = first.next;
System.out.print(first.value);
while(ptr != null){
System.out.print(" -> " + ptr.value);
ptr = ptr.next;
Node current = head;
while (current != null) {
System.out.print(current.value + " -> ");
current = current.next;
}
System.out.println(" -> null");
//The last element of the list points to null
System.out.println("null");
}

//Main function to run the LinkedList class
public static void main(String[] args){
// Main function to test the LinkedList class
public static void main(String[] args) {
LinkedList list = new LinkedList();
list.addAtEnd(new Node(5));
list.addAtEnd(new Node(7));
list.addAtFront(new Node(10));
list.addAtEnd(new Node(2));
list.addAtEnd(5);
list.addAtEnd(7);
list.addAtFront(10);
list.addAtEnd(2);

System.out.println("Linked List:");
list.print();
}

}
System.out.println("\nRemoving the first element:");
list.removeFront();
list.print();
}
}
28 changes: 19 additions & 9 deletions Python script to display ip address and host name.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
## importing socket module
import socket
## getting the hostname by socket.gethostname() method
hostname = socket.gethostname()
## getting the IP address using socket.gethostbyname() method
ip_address = socket.gethostbyname(hostname)
## printing the hostname and ip_address
print(f"Hostname: {hostname}")
print(f"IP Address: {ip_address}")
import socket as s
#get the host name
my_host = s.gethostname()

print('your name is' + my_host)
#get the IP address
my_ip = s.gethostbyname(my_host)

print('Your IP address is: ' + my_ip)

#Enter your own email
host = "yourname.com"

ip = s.gethostbyname(host)

print ('The IP address of ' + host + 'is' + ip)



60 changes: 55 additions & 5 deletions Python/passwordGenerator.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,57 @@
import random
import string
print("Welcome to the Password Generator!")
total = string.ascii_letters + string.digits + string.punctuation
length = int(input("How many characters would you like in your password? "))
password = "".join(random.sample(total, length))
print(f"Your secure password is: {password}")

def generate_password(length, include_upper, include_digits, include_special):
"""
Generate a secure password based on user preferences.

Parameters:
- length: int, the total length of the password.
- include_upper: bool, whether to include uppercase letters.
- include_digits: bool, whether to include digits.
- include_special: bool, whether to include special characters.

Returns:
- str: Generated password.
"""
if length < 4:
return "Password length must be at least 4 characters for security."

lower = string.ascii_lowercase
upper = string.ascii_uppercase if include_upper else ""
digits = string.digits if include_digits else ""
special = string.punctuation if include_special else ""

# Ensure password has at least one character from each selected group
mandatory_chars = (
random.choice(lower) +
(random.choice(upper) if include_upper else "") +
(random.choice(digits) if include_digits else "") +
(random.choice(special) if include_special else "")
)

# Fill the rest of the password length with a random mix of the selected groups
all_chars = lower + upper + digits + special
if len(all_chars) < 1:
return "Please select at least one character type."

remaining_length = length - len(mandatory_chars)
random_chars = "".join(random.choices(all_chars, k=remaining_length))

# Combine mandatory and random characters, then shuffle to randomize order
password = list(mandatory_chars + random_chars)
random.shuffle(password)
return "".join(password)

# User interaction
print("Welcome to the Advanced Password Generator!")
try:
length = int(input("Enter the desired length of your password (minimum 4): "))
include_upper = input("Include uppercase letters? (y/n): ").strip().lower() == 'y'
include_digits = input("Include digits? (y/n): ").strip().lower() == 'y'
include_special = input("Include special characters? (y/n): ").strip().lower() == 'y'

password = generate_password(length, include_upper, include_digits, include_special)
print(f"Your secure password is: {password}")
except ValueError:
print("Invalid input. Please enter a valid number for the password length.")