Determine all functions $ f$ defined on the natural numbers that take values among the natural numbers for which
\[ (f(n))^p \equiv n\quad {\rm mod}\; f(p)
\]
for all $ n \in {\bf N}$ and all prime numbers $ p$.
1. Let \( P(n, p) \) denote the given assertion: 
   \[
   (f(n))^p \equiv n \pmod{f(p)}
   \]
   for all \( n \in \mathbb{N} \) and all prime numbers \( p \).

2. Consider \( P(p, p) \):
   \[
   (f(p))^p \equiv p \pmod{f(p)}
   \]
   This implies:
   \[
   p \equiv 0 \pmod{f(p)}
   \]
   Therefore, \( f(p) \) must be a divisor of \( p \). Since \( p \) is prime, \( f(p) \) can only be \( 1 \) or \( p \). Thus:
   \[
   f(p) \in \{1, p\}
   \]

3. If \( f(p) = 1 \) for all primes \( p \), then any such function works because:
   \[
   (f(n))^p = 1^p = 1 \equiv n \pmod{1}
   \]
   which is always true.

4. Now suppose there exists a prime \( q \) with \( f(q) = q \). 

5. Note that for any \( n \in \mathbb{N} \):
   \[
   f(n)^q \equiv n \pmod{q}
   \]
   This implies:
   \[
   f(n) \equiv n \pmod{q}
   \]

6. **Case 1:** There exists a prime \( q > 2 \) with \( f(q) = q \). By Dirichlet's theorem on arithmetic progressions, there are infinitely many primes \( r \) such that \( r \not\equiv 1 \pmod{q} \). For any such \( r \):
   - If \( f(r) = 1 \), then:
     \[
     1 \equiv r \pmod{q}
     \]
     which is not true since \( r \not\equiv 1 \pmod{q} \). Therefore, \( f(r) = r \) for infinitely many primes \( r \).

7. Thus, for these primes \( r \):
   \[
   f(n)^r \equiv n \pmod{r}
   \]
   This implies:
   \[
   r \mid f(n) - n
   \]
   Since this is true for infinitely many primes \( r \), it follows that:
   \[
   f(n) = n
   \]
   for all \( n \in \mathbb{N} \), which works.

8. **Case 2:** \( f(2) = 2 \) and \( f(q) = 1 \) for all primes \( q > 2 \). Then:
   \[
   f(n) \equiv n \pmod{2}
   \]
   We can verify that any function of this form works.

Conclusion:
The final solution set is:
\[
\boxed{f(n) = n}
\]
\[
\boxed{\text{any function for which } f(p) = 1 \text{ for all primes } p}
\]
\[
\boxed{\text{any function such that } f(2) = 2, f(p) = 1 \text{ for all primes } p > 2, \text{ and } f(n) \equiv n \pmod{2} \text{ for all } n \in \mathbb{N}}
\]