Categories
Python Snippets

A Concept for Generating Random Seeds with AI on Light Weight Devices

Obviously, this is nothing new, but I was thinking about the potential NSA backdoor in intel’s random number generator RDRAND and the vulnerabilities in the UNIX PRNG.

Many suggestions to get around this problem uses taking photos of something with natural randomness for “True Randomness” like Cloudflare’s LavaRand or Bruno Sanguinetti’s Quantum random number generation on a mobile phone proposal.

So this problem has been solved for years now so why did I even think about it?

I currently use an encrypted thumb drive to store keys and similar mission-critical data and was looking for better solutions and came across a DIY solution using an arm processor and that got me thinking about using a little camera sensor, maybe pointing at some gell in a box that you shake up to make bubbles but that would be quite large.

giving the device a cellular connection introduces its own problems but makes the device pocketable and inconspicuous, imagine you’re at work and you plug this big box and cable into your workstation you’re gonna get looks.

The bellow code has many issues one being using base64 to encode the only image allows for and entropy of 65536000000(with my dyslexic brain I can’t even read that number) and the code for that particular AI generation is open source but it also requires that you have the same model set and still the results still might not result in the same outcome but the idea is you run your own AI generation and handshake with your personal device.

import requests
import base64
import random

def faceRand():
    imageSeed = requests.get('https://thispersondoesnotexist.com/image')
    randomSeed = base64.b64encode(imageSeed.content)
    #cloudflares lavalamps got nothing on this

    random.seed(randomSeed)

    return random.random()

print(faceRand())
Categories
Python Snippets

Image ALT Scraping for Accessibility Reporting

In my last employment we had someone who’s job it was to update alt tags on images and shareholders and management needed reports on progress so I built a small script to just that as well as another to make suggestions for the alt tag using the google vision API.


import requests
import json
import sys
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options

URLS = [line.rstrip('\n') for line in open('urls')]

options = Options()
	
options.set_headless(True)
	
driver = webdriver.Firefox(options=options)

#driver = webdriver.Firefox()

print(URLS)

imageslist = []

i = 0
while i < len(URLS):
	
	print(URLS[i])
	
	try:
	
		driver.get(URLS[i])
	
		imageLen = driver.execute_script("return document.images.length;")
	
		b = 0
	
		while b < imageLen:
		
			imageslist.append(driver.execute_script("if(document.images[" + str(b) + "].alt == '' | 'null'){ return document.images[" + str(b) + "].src}"))
		
			print(imageslist[b])
		
			b += 1
	
		images = '\n'.join(str(e) for e in imageslist)
	
		with open("images", "a+") as file:
			file.write(URLS[i] + ': ' + images + '\n')
	
		i += 1
	
	except:
		
		print('Failed')
		
		i += 1

driver.quit()

import requests
import json
import sys



IP_API = 'https://api.ipify.org'

API_KEY = 'PASTE GOOGLE API KEY HERE'

POST_URL = 'https://vision.googleapis.com/v1/images:annotate'

URLS = [line.rstrip('\n') for line in open('urls')]

ip_address = requests.get(IP_API).text

print(URLS)

i = 0
while i < len(URLS):
  print(URLS[i])
  resp = requests.post(
        'https://vision.googleapis.com/v1/images:annotate?key=' + API_KEY,
        json = {
          "requests": [{
            "image": {
              "source": {
			    "imageUri": URLS[i]
			    }
            },
            "features": [{
               "type": "LABEL_DETECTION",
              "maxResults": 3
            }]
          }]
        }
    )
  
  data = resp.json()
  
  print(data)
  
  try:
      
      json_data = data["responses"][0]["labelAnnotations"][0]["description"] + " " + data["responses"][0]["labelAnnotations"][1]["description"] + " " + data["responses"][0]["labelAnnotations"][2]["description"]
	  
  except:
    
      json_data = "An Error Occurreed"
  
  print(json_data)
  
  with open("alts", "a+") as file:
    file.write(URLS[i] + '\n' + 'Description: ' + json_data + '\n')

  i += 1