Skip to main content

Bubble sort

Nov 19, 2022CodeCatch
Loading...

More Python Posts

Untitled

Sep 14, 2024rgannedo-6205

0 likes • 4 views

# Python binary search function
def binary_search(arr, target):
left = 0
right = len(arr) - 1
while left <= right:
mid = (left + right) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
left = mid + 1
else:
right = mid - 1
return -1
# Usage
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
target = 7
result = binary_search(arr, target)
if result != -1:
print(f"Element is present at index {result}")
else:
print("Element is not present in array")

Calculate Square Root

Nov 18, 2022AustinLeath

0 likes • 4 views

# Python Program to calculate the square root
num = float(input('Enter a number: '))
num_sqrt = num ** 0.5
print('The square root of %0.3f is %0.3f'%(num ,num_sqrt))

Untitled

Sep 14, 2024rgannedo-6205

0 likes • 2 views

https://codecatch.net/post/06c9f5b7-1e00-40dc-b436-b8cccc4b69be

find parity outliers

Nov 19, 2022CodeCatch

0 likes • 4 views

from collections import Counter
def find_parity_outliers(nums):
return [
x for x in nums
if x % 2 != Counter([n % 2 for n in nums]).most_common()[0][0]
]
find_parity_outliers([1, 2, 3, 4, 6]) # [1, 3]

screencap.py

Jan 23, 2021asnark

0 likes • 0 views

"""
Take screenshots at x interval - make a movie of doings on a computer.
"""
import time
from datetime import datetime
import ffmpeg
import pyautogui
while True:
epoch_time = int(time.time())
today = datetime.now().strftime("%Y_%m_%d")
filename = str(epoch_time) + ".png"
print("taking screenshot: {0}".format(filename))
myScreenshot = pyautogui.screenshot()
myScreenshot.save(today + "/" + filename)
time.sleep(5)
#
# and then tie it together with: https://github.com/kkroening/ffmpeg-python/blob/master/examples/README.md#assemble-video-from-sequence-of-frames
#
"""
import ffmpeg
(
ffmpeg
.input('./2021_01_22/*.png', pattern_type='glob', framerate=25)
.filter('deflicker', mode='pm', size=10)
.filter('scale', size='hd1080', force_original_aspect_ratio='increase')
.output('movie.mp4', crf=20, preset='slower', movflags='faststart', pix_fmt='yuv420p')
.run()
)
"""

Untitled

Jun 26, 2025AustinLeath

0 likes • 1 view

def parse_ike_proposal(proposal):
"""
Parse an IKE proposal string to extract encryption, hash, PRF, and DH group in human-readable format.
Args:
proposal (str): IKE proposal string, e.g., 'IKE:AES_CBC_128/HMAC_SHA1_96/PRF_HMAC_SHA1/MODP_1024'
Returns:
dict: Dictionary with encryption, hash, PRF, and DH group in human-readable format
"""
dh_mapping = {
'MODP_1024': 'Group 2',
'MODP_2048': 'Group 14',
'MODP_3072': 'Group 15',
'MODP_4096': 'Group 16',
'MODP_6144': 'Group 17',
'MODP_8192': 'Group 18',
'ECP_256': 'Group 19',
'ECP_384': 'Group 20',
'ECP_521': 'Group 21',
'MODP_1024_160': 'Group 22',
'MODP_2048_224': 'Group 23',
'MODP_2048_256': 'Group 24'
}
enc_mapping = {
'AES_CBC_128': 'AES-128',
'AES_CBC_256': 'AES-256'
}
hash_mapping = {
'HMAC_SHA1_96': 'SHA1',
'HMAC_SHA2_256_128': 'SHA2-256',
'HMAC_SHA2_384_192': 'SHA2-384',
'HMAC_SHA2_512_256': 'SHA2-512'
}
prf_mapping = {
'PRF_HMAC_SHA1': 'SHA1',
'PRF_HMAC_SHA2_256': 'SHA2-256',
'PRF_HMAC_SHA2_384': 'SHA2-384',
'PRF_HMAC_SHA2_512': 'SHA2-512'
}
# Split the proposal into components
components = proposal.split('/')
# Initialize result dictionary
result = {
'encryption': 'Unknown',
'hash': 'Unknown',
'prf': 'Unknown',
'dh_group': 'Unknown'
}
# Extract components based on expected length
if len(components) >= 4:
result['encryption'] = enc_mapping.get(components[0].replace('IKE:', ''), 'Unknown')
result['hash'] = hash_mapping.get(components[1], 'Unknown')
result['prf'] = prf_mapping.get(components[2], 'Unknown')
result['dh_group'] = dh_mapping.get(components[3], 'Unknown')
elif len(components) == 3: # Handle cases without DH group
result['encryption'] = enc_mapping.get(components[0].replace('IKE:', ''), 'Unknown')
result['hash'] = hash_mapping.get(components[1], 'Unknown')
result['prf'] = prf_mapping.get(components[2], 'Unknown')
return result
def process_proposals(proposal_list):
"""
Process a list of IKE proposals and convert each to its human-readable components.
Args:
proposal_list (str): Comma-separated string of IKE proposals
Returns:
dict: Dictionary mapping each proposal to its parsed components
"""
proposals = proposal_list.split(', ')
result = {}
for proposal in proposals:
parsed = parse_ike_proposal(proposal.strip())
result[proposal] = parsed
return result
# Example usage
if __name__ == "__main__":
proposals = 'IKE:AES_CBC_128/HMAC_SHA1_96/PRF_HMAC_SHA1/MODP_1024, IKE:AES_CBC_128/HMAC_SHA1_96/PRF_HMAC_SHA1/MODP_2048, IKE:AES_CBC_128/HMAC_SHA1_96/PRF_HMAC_SHA1/MODP_3072, IKE:AES_CBC_128/HMAC_SHA1_96/PRF_HMAC_SHA1/MODP_4096, IKE:AES_CBC_128/HMAC_SHA1_96/PRF_HMAC_SHA1/MODP_6144, IKE:AES_CBC_128/HMAC_SHA1_96/PRF_HMAC_SHA1/MODP_8192, IKE:AES_CBC_128/HMAC_SHA1_96/PRF_HMAC_SHA1/ECP_256, IKE:AES_CBC_128/HMAC_SHA1_96/PRF_HMAC_SHA1/ECP_384, IKE:AES_CBC_128/HMAC_SHA1_96/PRF_HMAC_SHA1/ECP_521, IKE:AES_CBC_128/HMAC_SHA1_96/PRF_HMAC_SHA1/MODP_1024_160, IKE:AES_CBC_128/HMAC_SHA1_96/PRF_HMAC_SHA1/MODP_2048_224, IKE:AES_CBC_128/HMAC_SHA1_96/PRF_HMAC_SHA1/MODP_2048_256, IKE:AES_CBC_128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/MODP_1024, IKE:AES_CBC_128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/MODP_2048, IKE:AES_CBC_128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/MODP_3072, IKE:AES_CBC_128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/MODP_4096, IKE:AES_CBC_128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/MODP_6144, IKE:AES_CBC_128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/MODP_8192, IKE:AES_CBC_128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/ECP_256, IKE:AES_CBC_128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/ECP_384, IKE:AES_CBC_128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/ECP_521, IKE:AES_CBC_128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/MODP_1024_160, IKE:AES_CBC_128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/MODP_2048_224, IKE:AES_CBC_128/HMAC_SHA2_256_128/PRF_HMAC_SHA2_256/MODP_2048_256, IKE:AES_CBC_128/HMAC_SHA2_384_192/PRF_HMAC_SHA2_384/MODP_1024, IKE:AES_CBC_128/HMAC_SHA2_384_192/PRF_HMAC_SHA2_384/MODP_2048, IKE:AES_CBC_128/HMAC_SHA2_384_192/PRF_HMAC_SHA2_384/MODP_3072, IKE:AES_CBC_128/HMAC_SHA2_384_192/PRF_HMAC_SHA2_384/MODP_4096, IKE:AES_CBC_128/HMAC_SHA2_384_192/PRF_HMAC_SHA2_384/MODP_6144, IKE:AES_CBC_128/HMAC_SHA2_384_192/PRF_HMAC_SHA2_384/MODP_8192, IKE:AES_CBC_128/HMAC_SHA2_384_192/PRF_HMAC_SHA2_384/ECP_256, IKE:AES_CBC_128/HMAC_SHA2_384_192/PRF_HMAC_SHA2_384/ECP_384, IKE:AES_CBC_128/HMAC_SHA2_384_192/PRF_HMAC_SHA2_384/ECP_521, IKE:AES_CBC_128/HMAC_SHA2_384_192/PRF_HMAC_SHA2_384/MODP_1024_160, IKE:AES_CBC_128/HMAC_SHA2_384_192/PRF_HMAC_SHA2_384/MODP_2048_224, IKE:AES_CBC_128/HMAC_SHA2_384_192/PRF_HMAC_SHA2_384/MODP_2048_256, IKE:AES_CBC_128/HMAC_SHA2_512_256/PRF_HMAC_SHA2_512/MODP_1024, IKE:AES_CBC_128/HMAC_SHA2_512_256/PRF_HMAC_SHA2_512/MODP_2048, IKE:AES_CBC_128/HMAC_SHA2_512_256/PRF_HMAC_SHA2_512/MODP_3072, IKE:AES_CBC_128/HMAC_SHA2_512_256/PRF_HMAC_SHA2_512/MODP_4096, IKE:AES_CBC_128/HMAC_SHA2_512_256/PRF_HMAC_SHA2_512/MODP_6144, IKE:AES_CBC_128/HMAC_SHA2_512_256/PRF_HMAC_SHA2_512/MODP_8192, IKE:AES_CBC_128/HMAC_SHA2_512_256/PRF_HMAC_SHA2_512/ECP_256'
result = process_proposals(proposals)
for proposal, parsed in result.items():
print(f"Encryption={parsed['encryption']}, Hash={parsed['hash']}, PRF={parsed['prf']}, DH Group={parsed['dh_group']}")