Modular arithmetics I've been reading about some examples concerning DSS/DSA signature security and there is one part of an example that I do not understand the maths. Namely, how do you calculate this:
$w = (s^{-1}$ $mod$ $q)$ 
In this example let's say $q = 13$ and $s = 10$.
So we have
$w = (10^{-1}$ $mod$ $13) = 4$ 
How do we get 4 as a result? 

Inverses modulo small integers are usually quickly computable by fraction fiddling. For example
$\rm\ mod\ 13\!:\, \ \begin{eqnarray}1\,\equiv&& -12\\ 10\,\equiv&& -3\end{eqnarray}\,\ \Rightarrow\,\ \dfrac{1}{10}\,\equiv\, \dfrac{-12}{-3}\,\equiv\, 4,\ $ indeed $\,\ 4\cdot 10 = 3\cdot 13 + 1\equiv 1\pmod{13}$
For larger moduli one may use the Extended Euclidean Algorithm. Given integers $\rm\,x,y\,$ it yields integers $\rm\,a,b\,$ such that $\rm\, ax+by = gcd(x,y)\ $ (Bezout's identity). Thus, when the gcd $=1,\,$ 
$$\ \rm ax+by = 1\ \Rightarrow\ ax\equiv 1\!\!\pmod y$$
yielding the inverse of $\rm\,x,\,$ modulo $\rm\,y,\,$ i.e. $\,
 \rm x^{-1} = 1/x\, \equiv\, a\pmod y$
Beware $\ $ The use of fractions in modular arithmetic is valid only when the denominator is invertible. Otherwise the quotient need not be unique, e.g. mod $\rm\:10,\:$ $\rm\:4\,x\equiv 2\:$ has solutions $\rm\:x\equiv 3,8,\:$ so the "fraction" $\rm\:x \equiv 2/4\pmod{10}\,$ cannot designate a unique solution of $\,4x\equiv 2.\,$ Indeed, the solution is $\rm\:x\equiv 1/2\equiv 3\pmod 5,\,$ which requires canceling $\,2\,$ from the modulus too, since $\rm\:10\:|\:4x-2\iff5\:|\:2x-1.\:$
Generally the grade-school rules of fraction arithmetic apply universally (i.e. in all rings) where the denominators are invertible. This fundamental property will be clarified conceptually when one learns in university algebra about the universal properties of fractions rings and localizations.
