[DevDiary] Adversarial Algorithms Against AI Image Synthesis: A Computational Formalization Using Fortran

Introduction

Recently, technologies designed to counter
the indiscriminate crawling of artistic styles by
AI have been gaining significant attention.

Drawing inspiration from the mechanism of Nightshade—widely
regarded as the most potent among them—
I have explored how to implement this within a modern

C# environment (specifically optimized for 4-core CPUs and memory efficiency).
To ensure a rigorous examination of the pure logical flow,
I have drafted the architectural blueprint using Fortran,

a language renowned for its unparalleled efficiency in numerical arrays
and scientific computation.


1. A Computational Approach: Perturbation of the Feature Space

AI perceives images as high-dimensional vectors
rather than mere pixels.
My objective is to ‘minimize visual disparity while maximizing
the displacement within the vector space.’

Core Data Structures (Memory Efficiency)

To optimize L3 cache efficiency for the i5-4460,
the structure utilizes Fortran’s contiguous array mapping,
which is natively optimized for SIMD operations.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
module DataStructures
implicit none

! Managing pixel data as linear 1D memory instead of 3D arrays.
! Design for leveraging C#'s Span<float> and Fortran's contiguous pointers.
type :: TLinearTensor
real(4), allocatable :: Data(:) ! 32-bit Floating Point (Single Precision)
integer :: Width, Height, Channels
integer(8) :: TotalSize
end type TLinearTensor

! Defining the Target Concept to Mislead the AI
type :: TConceptAnchor
real(4) :: Vector(0:767) ! Fake Indicators (e.g., Dog Image → Cat Vector)
end type TConceptAnchor
end module DataStructures

2. Core Algorithm: PGD (Projected Gradient Descent)

This is not simple noise, but a precise procedure to refine poisoning
data through the reverse-calculation of the AI’s feature extraction layers.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
! [Algorithm] Projected Gradient Descent: Core Routine for Poisoning While Preserving Originality
subroutine InjectPoison(Img, Config, Epsilon)
use ImageTypes
implicit none

type(TLinearTensor), intent(inout) :: Img
type(TConceptAnchor), intent(in) :: Config
real(4), intent(in) :: Epsilon

integer :: i, p
real(4) :: Gradient, Delta

! Finely adjusting the poison over a set number of iterations.
do i = 1, 50
! 1. Feature Extraction Simulation
! (AI model inference logic would be called here)

do p = 1, int(Img%TotalSize)
! 2. Gradient Calculation
! Deriving the direction in which pixels must be adjusted to move toward the target concept.
Gradient = CalculateGradient(Img%Data(p), Config%Vector(mod(p-1, 768)))

! 3. Poisoning (Step Update)
Img%Data(p) = Img%Data(p) - (0.005 * sign(1.0, Gradient))

! 4. Projection: Constraining Disparities to Ensure Visual Imperceptibility
Delta = Img%Data(p) - OriginalData(p)
if (abs(Delta) > Epsilon) then
Img%Data(p) = OriginalData(p) + (sign(1.0, Delta) * Epsilon)
end if
end do
end do
end subroutine InjectPoison

3. Hardware Optimization: Quad-Core Utilization and Addressing I/O Bottlenecks

Considering the 13-year-old PC specifications, Disk I/O and Garbage
Collection (GC) are far more daunting than raw computational speed.

Multi-Stage Pipeline Architecture

Using C#’s System.Threading.Channels,

  • Core 1 (Loader): Pre-reads images from the

    SSD and loads them into a memory pool
  • Core 2 & 3 (Processors): Executing the InjectPoison

    logic at high speed using AVX2 (SIMD) instructions, processing 8 pixels at a time.
  • Core 4 (Saver): Saves the processed images in lossless formats, such as PNG.

4. The Essence of the Mechanism: Ensuring Robustness

To ensure the poisoning effect persists even when
the AI rotates or resizes images during
training, the concept of
EOT (Expectation Over Transformation) is essential.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
! A logic that ensures the poison remains effective on average across various transformed states.
function CalculateRobustPoison(Img) result(AggregatedGrad)
use ImageTypes
implicit none

type(TLinearTensor), intent(in) :: Img
real(4) :: AggregatedGrad
type(TLinearTensor) :: TempImg
integer :: t

AggregatedGrad = 0.0
! Testing under five different transformation states, including rotation, scaling, and noise injection.
do t = 1, 5
TempImg = ApplyTransformation(Img, t)
AggregatedGrad = AggregatedGrad + GetLoss(TempImg)
end do

! Identifying the averaged vulnerabilities to launch a unified adversarial attack.
AggregatedGrad = AggregatedGrad / 5.0
end function CalculateRobustPoison

5. Conclusion and Future Work

While adopting the core concepts of Nightshade,

the actual implementation prioritizes

hardware-specific optimizations for the i5-4460,

specifically focusing on memory pooling and SIMD vectorization.

Limited hardware environments, such as a 13-year-old legacy PC,

do not necessitate

compromise. On the contrary,
these constraints highlight the true value of computational

optimization. The subsequent phase of this research will involve

integrating C# and TorchSharp within the Visual Studio 2022 environment

to develop a functional model based on this Fortran-derived architecture.



Thank you very much for taking the time to read through this long journey.

I wish you all a wonderful day. : )