Let $$p(n) = \#\{f:\mathbb N \to \{0,1\} \mid n \text{ is the shortest period of } f\}$$ that means $p(n)$ denotes the number of binary sequences of period exactly $n$ (and no less). Is there a way to compute $p(n)$ without just bruteforcing all possibilities?
For an $f$ of period $n$ the values $f(1),f(2),\ldots,f(n)$ already define $f$ completely, so here are some lists of such $f$ for small $n$ (I hope it is correct):
$$ \begin{array}{c|l|l} n & \text{list} & p(n) \\ \hline 1 & (0),(1) & 2 \\ \hline 2 & (0,1),(1,0) & 2 \\ \hline 3 & (0,0,1),(0,1,0),(1,0,0),(0,1,1),(1,0,1),(1,1,0) & 6 \\ \hline 4 & (0,0,0,1),(0,0,1,0),(0,1,0,0),(1,0,0,0) & 12 \\ & (1,1,1,0),(1,1,0,1),(1,0,1,1),(0,1,1,1) & \\ & (1,0,0,1),(0,1,1,0) ,(1,1,0,0),(0,0,1,1)& \end{array} $$
Here's one way
$$f(n) = 2^n - \sum_{1\leq i<n,n\mid i} f(i)$$
In English this reads as
The idea behind this is if we can find the number of length $n$ sequences that are periodic we can find the number of ones that are not, since we know the number of total sequences.
We know that every periodic sequence is composed of some unique aperiodic sequence a number of times and that each of these aperiodic sequences has size $k$ such that $n\mid k$. Thus we are looking for the number of aperiodic sequences sequences of length that divide $n$. This would just be the sum of our function applied to every proper divisor of $n$.
This lends itself to a rather neat little algorithm, which I have implemented in Haskell.
Try it online!
The algorithm is not terribly fast because we are still required to factor $n$, so there is definitely room for improvement.