#!/usr/bin/sbcl --script (defpackage #:my-package (:use #:opticl #:cl)) (in-package #:my-package) #|hopefully a lisp script to hide one image in another will need to read in the pixel 8 bit values of another image then read in the pixel 1bit values of a black and white image then place the values of the latter into the lsb of the former |# (defparameter *hide-in* (read-png-file (second *posix-argv*))) (defparameter *to-hide*(read-png-file (third *posix-argv*))) (defparameter *hide-path* (fourth *posix-argv*)) ;;;This should map the value between 0 - 255 to a 3 bit binary number (defun change-num (n) "Takes in a value between 0 - 255 and returns an array of size 3 with the corresponding 3 bit binary array inside" (cond ((or (<= 0 n 36)) #(0 0 0)) ((or (<= 36 n 72)) #(0 0 1)) ((or (<= 72 n 108)) #(0 1 0)) ((or (<= 108 n 144)) #(0 1 1)) ((or (<= 144 n 180)) #(1 0 0)) ((or (<= 180 n 216)) #(1 0 1)) ((or (<= 216 n 240)) #(1 1 0)) (t #(1 1 1)))) ;;;This should take in a gray scale png data in a 3D array and return the original pixel values ;;;from 0-255 replaced with the arrays produced by map-num (defun change-gray-scale-image-to-3d (gray-scale-array) "Returns a new array that is of 3 dimensions instead of 2 with the pixel values converted to a simple-vector size 3 with 3 bits inside instead of a value between 0 - 255" (let* ((dimensions (array-dimensions gray-scale-array)) (new-array (make-array (list (first dimensions)(second dimensions) 3) :element-type 'bit))) (dotimes (x (first dimensions)) (dotimes (y (second dimensions)) (dotimes (z 3) (setf (aref new-array x y z) (aref (change-num (aref gray-scale-array x y)) z))))) new-array)) (defun hide-gray-in-byte (bit rgb) "Takes in a bit (the gray value) and an rgb value (0 - 255) and returns the rgb value with the gray bit hidden inside" (if (zerop bit) (if (evenp rgb) rgb (1- rgb)) (if (oddp rgb) rgb (1+ rgb)))) (defun find-gray-in-byte (rgb) "Takes in an rgb value (0 - 255) and returns the new gray value" (if (oddp rgb) 0 255)) (defun hide-gray-in-image (gray-scale-3d-array rgb-3d-array) "Hides the entirety of the gray-scale-3d-array inside a copy of the rgb-vector, it then returns said copy. Gray scale must be smaller or equal in size to the rgb" (let* ((copy rgb-3d-array) (dimensions (array-dimensions gray-scale-3d-array))) (dotimes (x (first dimensions) copy) (dotimes (y (second dimensions)) (dotimes (z 3) (setf (aref copy x y z) (hide-gray-in-byte (aref gray-scale-3d-array x y z) (aref rgb-3d-array x y z)))))))) (defun find-gray-in-image (rgb-3d-array) "Generates a new 3d array containing the hidden image and returns said array" (let* ((copy rgb-3d-array) (dimensions (array-dimensions copy))) (dotimes (x (first dimensions) copy) (dotimes (y (second dimensions)) (dotimes (z 3) (setf (aref copy x y z) (find-gray-in-byte (aref rgb-3d-array x y z)))))))) (defun check-equal (a b) (dotimes (x 16) (dotimes (y 16) (dotimes (z 3) (format t "A~A B~A~%" (aref a x y z) (aref b x y z)))))) (defun hide-image () "Hides the gray-scale image inside the rgb-png and exports as a new png named in pathname" (if (= 3 (length (array-dimensions *to-hide*))) (let ((hidden-image (hide-gray-in-image *to-hide* *hide-in*))) (write-png-file *hide-path* hidden-image) (format t "Done~%")) (let* ((converted (change-gray-scale-image-to-3d *to-hide*)) (hidden-image (hide-gray-in-image converted *hide-in*))) (write-png-file *hide-path* hidden-image) (format t "Done~%")))) (defun extract-gray (to-extract-pathname extracted-pathname) "Extracts the grayscale image" (let ((image (find-gray-in-image (read-png-file to-extract-pathname)))) (write-png-file extracted-pathname image)) (format t "Done~%")) (hide-image)